Пример #1
0
 def testSimplePrompt(self):
     self.assertSerialize({
         'type': 'doctest',
         'test': formatting.dedent("""
         >>> square(-2)
         4
         """),
     })
Пример #2
0
 def testLocked(self):
     self.assertSerialize({
         'type': 'doctest',
         'test': formatting.dedent("""
         >>> square(-2)
         5
         # locked
         """),
     })
Пример #3
0
 def testExplanation(self):
     self.assertSerialize({
         'type': 'doctest',
         'test': formatting.dedent("""
         >>> square(-2)
         4
         # explanation: Squares a negative number
         """),
     })
Пример #4
0
 def testMultiplePrompts(self):
     self.assertSerialize({
         'type': 'doctest',
         'test': formatting.dedent("""
         >>> square(-2)
         4
         >>> x = 4
         >>> square(x)
         16
         """),
     })
Пример #5
0
 def testMultipleChoice(self):
     self.assertSerialize({
         'type': 'doctest',
         'test': formatting.dedent("""
         >>> square(-2)
         4
         # choice: 0
         # choice: 2
         # choice: -4
         """),
     })
Пример #6
0
 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
         """)
     })
Пример #7
0
 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))
Пример #8
0
    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 = []
Пример #9
0
 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
Пример #10
0
 def assertFormat(self, expect, json):
     self.assertEqual(formatting.dedent(expect),
                      formatting.prettyjson(json))
Пример #11
0
 def __init__(self, **fields):
     super().__init__(**fields)
     self['question'] = formatting.dedent(self['question'])
     self['answer'] = formatting.dedent(self['answer'])