-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add repr method and several tests (#5)
* Add representation of TrafaretValidator * Add smoke tests
- Loading branch information
Showing
4 changed files
with
39 additions
and
1 deletion.
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
Empty file.
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,26 @@ | ||
from unittest import TestCase | ||
|
||
import trafaret as t | ||
|
||
from trafaret_validator import TrafaretValidator | ||
|
||
|
||
class ValidatorForTest(TrafaretValidator): | ||
d = t.Int() | ||
|
||
|
||
class TestTrafaretValidator(TestCase): | ||
|
||
def test_valid(self): | ||
data = {'d': 1} | ||
vld_good = ValidatorForTest(**data) | ||
self.assertTrue(vld_good.validate()) | ||
self.assertEqual(data, vld_good.data) | ||
self.assertEqual({}, vld_good.errors) | ||
|
||
def test_invalid(self): | ||
data = {'d': 'asdasdasd'} | ||
vld_good = ValidatorForTest(**data) | ||
self.assertFalse(vld_good.validate()) | ||
self.assertEqual({}, vld_good.data) | ||
self.assertIn('d', vld_good.errors) |
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