Skip to content

Instantly share code, notes, and snippets.

@impredicative
Created April 18, 2017 14:44
Show Gist options
  • Save impredicative/4e6d1a48eab23ef51546749adc969220 to your computer and use it in GitHub Desktop.
Save impredicative/4e6d1a48eab23ef51546749adc969220 to your computer and use it in GitHub Desktop.
TestCases class
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