Created
April 18, 2017 14:44
-
-
Save impredicative/4e6d1a48eab23ef51546749adc969220 to your computer and use it in GitHub Desktop.
TestCases class
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
class TestCases: | |
def __init__(self, **defaults): | |
self._defaults = defaults | |
self._cases = [] | |
self._next_index = 0 | |
def __iter__(self): | |
return self | |
def __next__(self): | |
try: | |
case = self._cases[self._next_index] | |
except IndexError: | |
raise StopIteration | |
self._next_index += 1 | |
return Namespace(_customizations=case, **ChainMap(case, self._defaults)) | |
def add_case(self, **case): | |
self._cases.append(case) | |
def add_cases(self, *cases): | |
for case in cases: | |
self.add_case(**case) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment