Metadata-Version: 1.0
Name: Minos
Version: 0.1
Summary: Minos is a library to do flexible validation of Python objects
Home-page: https://github.com/uber/minos
Author: Kevin Novak
Author-email: kevin@uber.com
License: UNKNOWN
Description: ['Minos: A Lightweight Validation Framework\n', '=========================================\n', '`Minos` is a library that you can use in your code to create a simple validation\n', 'framework. Its aim is to provide a lightweight interface of functions that make it\n', 'simple to quickly build and manipulate models.\n', '\n', '.. toctree::\n', '   :maxdepth: 2\n', '\n', 'Installation\n', '============\n', '\n', 'To install Minos locally:\n', '\n', '::\n', '\n', '    $ python setup.py develop\n', '\n', '\n', 'Minos will soon be on PyPi.\n', '\n', '.. _Quickstart:\n', '\n', 'Quickstart\n', '==========\n', '\n', 'There are a few patterns Minos was designed to support; class validation with validators declared as\n', 'part of the class definition, class validation where the validators are declared seperately, and as\n', 'totally independant object validators. See below for a few examples of each pattern.\n', '\n', 'Class Validators in Class Definition\n', '------------------------------------\n', '\n', 'To declare validators inside of a class, the class needs to inherit from the Minos Mixin, and the\n', 'validation arguments are passed to each validator on instantiation.\n', '\n', 'For example, given a class definition like so:\n', '\n', '.. sourcecode:: python\n', '\n', '      import minos\n', '      import pytz\n', '\n', '      from datetime import datetime\n', '      from minos.validators import DatetimeValidator, NumericalityValidator, PresenceValidator\n', '\n', '\n', '      class Toaster(minos.Mixin):\n', '\n', '          #Attributes\n', '\n', '          created_at = None\n', '          num_slots = None\n', '\n', '          #Validators\n', '\n', '          validators = [\n', "              DatetimeValidator('created_at'),\n", "              PresenceValidator('num_slots'),  # every toaster needs to have its number of slots specified\n", '              #Toasters can only have an integer number of slots between 2-8\n', '              NumericalityValidator(\n', "                  'num_slots',\n", '                  integer_only=True,\n', '                  greater_than_or_equal_to=2,\n', '                  less_than_or_equal_to=8\n', '              )\n', '          ]\n', '\n', '\n', '          def __init__(self, bread):\n', '              self.bread = bread\n', '              self.created_at = datetime.now(pytz.utc)\n', '\n', '          #...class definition continues...\n', '\n', '\n', 'When using the ToasterClass in code, you can do stuff like this:\n', '\n', '.. sourcecode:: python\n', '\n', '      def toast_bread(bread):\n', '          toaster = Toaster(num_slots=4)\n', '          try:\n', "              toaster.validate()  # Validates that toaster's attributes are valid\n", '          except minos.errors.FormValidationError:\n', '              raise ToastError("can\'t toast bread, toasters busted.")\n', '\n', '          toasted_bread = toaster.toast(bread)\n', '\n', '          return toasted_bread\n', '\n', 'Class Validators Outside Class Definition\n', '-----------------------------------------\n', '\n', 'Similarly, You can also create a validator that validates a single attribute of a python object,\n', "and pass objects to be validated to it using the Validator's *.validate_wrapper()* call.\n", '\n', '\n', '.. sourcecode:: python\n', '\n', '      import minos\n', '      from minos.validators import NumericalityValidator\n', '\n', "      #Create a validator that for a toaster's slots ahead of time\n", '      slot_validator = NumericalityValidator(\n', "          'num_slots',\n", '          integer_only=True,\n', '          greater_than_or_equal_to=2,\n', '          less_than_or_equal_to=8\n', '      )\n', '\n', '      #Given a list of toasters, validate them all\n', '      for toaster in [dorm_toaster, kitchen_toaster, fancy_toaster]:\n', '          try:\n', '              #Check this toaster using the parameters specified earlier\n', '              slot_validator.validate_wrapper(toaster)\n', '          except minos.errors.FormValidationError:\n', '              print "{} doesn\'t have the right number of slots.".format(toaster.name)\n', '\n', 'Single\\-Use Validation\n', '----------------------\n', '\n', 'You can also create validators without configuration, and specify the configuration inline using the *.validate()* call:\n', '\n', '\n', '.. sourcecode:: python\n', '\n', '      from minos.validators import NumericalityValidator\n', '      from minos.errors import ValidationError\n', '\n', '      #Make a validator that checks numeric qualities of objects\n', '      accountant = NumericalityValidator()\n', '\n', '\n', '      #Check a bunch of stuff\n', '\n', '      try:\n', '          accountant.validate(bank_account, greater_than=0)\n', '      except ValidationError:\n', '          print "You\'re broke!"\n', '\n', '      try:\n', '          accountant.validate(tax_payment, greater_than=0, less_than=5000.00)\n', '      except ValidationError:\n', '          print "You\'re tax payment doesn\'t seem right..."\n', '\n', '      try:\n', '          accountant.validate(num_deductions, integer_only=True)\n', '      except ValidationError:\n', '          print "Your number of deductions doesn\'t make sense."\n', '\n', '\n']
Keywords: tests,validation
Platform: UNKNOWN
Classifier: Development Status :: 3 - Alpha
Classifier: Programming Language :: Python
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Topic :: Software Development :: Testing
Classifier: Topic :: Software Development :: Libraries :: Python Modules
