def testSimplePrompt(self): self.assertSerialize({ 'type': 'doctest', 'test': formatting.dedent(""" >>> square(-2) 4 """), })
def testLocked(self): self.assertSerialize({ 'type': 'doctest', 'test': formatting.dedent(""" >>> square(-2) 5 # locked """), })
def testExplanation(self): self.assertSerialize({ 'type': 'doctest', 'test': formatting.dedent(""" >>> square(-2) 4 # explanation: Squares a negative number """), })
def testMultiplePrompts(self): self.assertSerialize({ 'type': 'doctest', 'test': formatting.dedent(""" >>> square(-2) 4 >>> x = 4 >>> square(x) 16 """), })
def testMultipleChoice(self): self.assertSerialize({ 'type': 'doctest', 'test': formatting.dedent(""" >>> square(-2) 4 # choice: 0 # choice: 2 # choice: -4 """), })
def testTestParams(self): self.test['params'] = { 'doctest': { 'setup': 'x = 1', 'teardown': 'x = 2', 'cache': 'x = 3', } } self.assertSerialize({ 'type': 'doctest', 'test': formatting.dedent(""" >>> square(2) 4 """) })
def _format_lines(self): """Splits the test string and adds _Answer objects to denote prompts. """ self._lines = [] for line in formatting.dedent(self['test']).splitlines(): if not line: continue elif line.startswith(self.PS1) or line.startswith(self.PS2): self._lines.append(line) elif line.startswith('#'): # Assume the last object in lines is an _Answer. self._lines[-1].update(line) else: # Wrap the doctest answer in an object. self._lines.append(_Answer(line))
def __init__(self, **fields): """Constructor. PARAMETERS: input_str -- str; the input string, which will be dedented and split along newlines. outputs -- list of TestCaseAnswers test -- Test or None; the test to which this test case belongs. frame -- dict; the environment in which the test case will be executed. teardown -- str; the teardown code. This code will be executed regardless of errors. status -- keyword arguments; statuses for the test case. """ super().__init__(**fields) self['teardown'] = formatting.dedent(self['teardown']) self._lines = []
def __init__(self, **fields): super().__init__(**fields) self['setup'] = formatting.dedent(self['setup']) self['teardown'] = formatting.dedent(self['teardown']) self['cache'] = formatting.dedent(self['cache']) self._frame = None
def assertFormat(self, expect, json): self.assertEqual(formatting.dedent(expect), formatting.prettyjson(json))
def __init__(self, **fields): super().__init__(**fields) self['question'] = formatting.dedent(self['question']) self['answer'] = formatting.dedent(self['answer'])