Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve subclassability/extendability of attribute types.
Attribute now use class-scope defaults for most, if not all, Attribute properties. That allows subclasses to have a common setup, e.g. an Email type that is a String subclass that always provides a LooksLikeAnEmail validator. Purely as a nod to syntax, the default validator is an Always validator. That allows: SomeType(validator=All(SomeType.validator, MyValidator())) Instead of: SomeType(validator=(MyValidator() if not SomeType.validator else All(SomeType.validator, MyValidator()))) The 2nd version is very ugly and uses duplicate code.
- Loading branch information
Matt Goodall
committed
Nov 28, 2008
1 parent
fe82899
commit b08936a
Showing
5 changed files
with
132 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import unittest | ||
import schemaish | ||
|
||
|
||
class TestValidators(unittest.TestCase): | ||
|
||
def test_always(self): | ||
v = schemaish.Always() | ||
v.to_python('foo') | ||
v.to_python('') | ||
v.to_python(1) | ||
v.to_python([1,2,3]) | ||
v.to_python(None) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters