-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changed version to 0.8
- Loading branch information
Showing
5 changed files
with
58 additions
and
3 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,14 @@ | ||
def turn_on(): | ||
globals()['pyvalid_enabled'] = True | ||
|
||
|
||
def turn_off(): | ||
globals()['pyvalid_enabled'] = False | ||
|
||
|
||
def is_enabled(): | ||
if 'pyvalid_enabled' in globals(): | ||
enabled = globals()['pyvalid_enabled'] | ||
else: | ||
enabled = True | ||
return enabled |
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,33 @@ | ||
import unittest | ||
import pyvalid | ||
|
||
|
||
class TestSwitch(unittest.TestCase): | ||
|
||
def setUp(self): | ||
@pyvalid.returns(True) | ||
@pyvalid.accepts(True) | ||
def func1(val): | ||
return val | ||
self.func1 = func1 | ||
|
||
def test_default_state(self): | ||
# Validators must be enabled by default. | ||
self.assertTrue(pyvalid.switch.is_enabled()) | ||
|
||
def test_turn_off(self): | ||
pyvalid.switch.turn_off() | ||
val = self.func1(False) | ||
self.assertFalse(val) | ||
|
||
def test_turn_on(self): | ||
pyvalid.switch.turn_on() | ||
val = self.func1(True) | ||
self.assertTrue(val) | ||
self.assertRaises( | ||
pyvalid.ArgumentValidationError, self.func1, False | ||
) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |