Esempio n. 1
0
 def test_repr_with_description(self):
     # repr(placeholder) shows you how the object was constructed.
     test = PlaceHolder("test id", "description")
     self.assertEqual(
         "<testtools.testcase.PlaceHolder(%r, %r)>" % (
             test.id(), test.shortDescription()),
         repr(test))
Esempio n. 2
0
 def test_repr_with_description(self):
     # repr(placeholder) shows you how the object was constructed.
     test = PlaceHolder("test id", "description")
     self.assertEqual(
         "<testtools.testcase.PlaceHolder(%r, %r)>" % (
             test.id(), test.shortDescription()),
         repr(test))
Esempio n. 3
0
 def test_custom_suite_without_sort_tests_works(self):
     a = PlaceHolder('a')
     b = PlaceHolder('b')
     class Subclass(unittest.TestSuite):pass
     input_suite = Subclass([b, a])
     suite = sorted_tests(input_suite)
     self.assertEqual([b, a], list(iterate_tests(suite)))
     self.assertEqual([input_suite], list(iter(suite)))
Esempio n. 4
0
 def test_outcome_logs(self):
     test_id = self.getUniqueString()
     test = PlaceHolder(test_id, outcome=self.outcome)
     result = self.make_result_object()
     result.startTestRun()
     self.useFixture(AutopilotVerboseLogging())
     with FakeLogger() as log:
         test.run(result)
         self.assertThat(log.output, Contains(self.log % test_id))
Esempio n. 5
0
 def test_supplies_details(self):
     details = {'quux':None}
     test = PlaceHolder('foo', details=details)
     result = ExtendedTestResult()
     test.run(result)
     self.assertEqual(
         [('startTest', test),
          ('addSuccess', test, details),
          ('stopTest', test)],
         result._events)
Esempio n. 6
0
 def test_sorts_custom_suites(self):
     a = PlaceHolder('a')
     b = PlaceHolder('b')
     class Subclass(unittest.TestSuite):
         def sort_tests(self):
             self._tests = sorted_tests(self, True)
     input_suite = Subclass([b, a])
     suite = sorted_tests(input_suite)
     self.assertEqual([a, b], list(iterate_tests(suite)))
     self.assertEqual([input_suite], list(iter(suite)))
Esempio n. 7
0
 def test_supplies_details(self):
     details = {'quux':None}
     test = PlaceHolder('foo', details=details)
     result = ExtendedTestResult()
     test.run(result)
     self.assertEqual(
         [('startTest', test),
          ('addSuccess', test, details),
          ('stopTest', test)],
         result._events)
Esempio n. 8
0
 def test_multiple_duplicates(self):
     # If there are multiple duplicates on a test suite, we report on them
     # all.
     a = PlaceHolder('a')
     b = PlaceHolder('b')
     c = PlaceHolder('a')
     d = PlaceHolder('b')
     error = self.assertRaises(
         ValueError, sorted_tests, unittest.TestSuite([a, b, c, d]))
     self.assertThat(
         str(error),
         Equals("Duplicate test ids detected: {}".format(
             pformat({'a': 2, 'b': 2}))))
Esempio n. 9
0
 def test_enumerates_tests_before_run(self):
     io = BytesIO()
     runner = SubunitTestRunner(stream=io)
     test1 = PlaceHolder('name1')
     test2 = PlaceHolder('name2')
     case = unittest.TestSuite([test1, test2])
     runner.run(case)
     io.seek(0)
     eventstream = StreamResult()
     subunit.ByteStreamToStreamResult(io).run(eventstream)
     self.assertEqual([
         ('status', 'name1', 'exists'),
         ('status', 'name2', 'exists'),
     ], [event[:3] for event in eventstream._events[:2]])
Esempio n. 10
0
 def test_includes_timing_output(self):
     io = BytesIO()
     runner = SubunitTestRunner(stream=io)
     test = PlaceHolder('name')
     runner.run(test)
     client = TimeCollectingTestResult()
     io.seek(0)
     subunit.TestProtocolServer(client).readFrom(io)
     self.assertTrue(len(client.time_called) > 0)
Esempio n. 11
0
 def test_includes_timing_output(self):
     bytestream = io.BytesIO()
     runner = SubunitTestRunner(stream=bytestream)
     test = PlaceHolder('name')
     runner.run(test)
     bytestream.seek(0)
     eventstream = StreamResult()
     subunit.ByteStreamToStreamResult(bytestream).run(eventstream)
     timestamps = [event[-1] for event in eventstream._events
         if event is not None]
     self.assertNotEqual([], timestamps)
Esempio n. 12
0
    def test_addSuccess_calls_decorated_test(self):
        wrapped = Mock()
        result = testresult.LoggedTestResultDecorator(wrapped)
        fake_test = PlaceHolder('fake_test')
        fake_details = self.construct_simple_content_object()

        result.addSuccess(fake_test, fake_details)

        wrapped.addSuccess.assert_called_once_with(
            fake_test,
            details=fake_details
        )
Esempio n. 13
0
 def test_get_test_ids(self):
     repo = self.repo_impl.initialise(self.sample_url)
     inserter = repo.get_inserter()
     legacy_result = testtools.ExtendedToStreamDecorator(inserter)
     legacy_result.startTestRun()
     test_cases = [PlaceHolder(self.getUniqueString()) for r in range(5)]
     for test_case in test_cases:
         test_case.run(legacy_result)
     legacy_result.stopTestRun()
     run_id = inserter.get_id()
     self.assertEqual(run_id, repo.latest_id())
     returned_ids = repo.get_test_ids(run_id)
     self.assertEqual([test.id() for test in test_cases], returned_ids)
Esempio n. 14
0
 def test_id_comes_from_constructor(self):
     # The id() of a PlaceHolder is whatever you pass into the constructor.
     test = PlaceHolder("test id")
     self.assertEqual("test id", test.id())
 def test_duplicate_simple_suites(self):
     a = PlaceHolder('a')
     b = PlaceHolder('b')
     c = PlaceHolder('a')
     self.assertRaises(ValueError, sorted_tests,
                       unittest.TestSuite([a, b, c]))
 def test_sorts_simple_suites(self):
     a = PlaceHolder('a')
     b = PlaceHolder('b')
     suite = sorted_tests(unittest.TestSuite([b, a]))
     self.assertEqual([a, b], list(iterate_tests(suite)))
Esempio n. 17
0
 def test_id_comes_from_constructor(self):
     # The id() of a PlaceHolder is whatever you pass into the constructor.
     test = PlaceHolder("test id")
     self.assertEqual("test id", test.id())
Esempio n. 18
0
 def makePlaceHolder(self, test_id="foo", short_description=None):
     return PlaceHolder(test_id, short_description)
Esempio n. 19
0
 def test_shortDescription_is_id(self):
     # The shortDescription() of a PlaceHolder is the id, by default.
     test = PlaceHolder("test id")
     self.assertEqual(test.id(), test.shortDescription())
Esempio n. 20
0
 def test_repr_just_id(self):
     # repr(placeholder) shows you how the object was constructed.
     test = PlaceHolder("test id")
     self.assertEqual(
         "<testtools.testcase.PlaceHolder(%s)>" % repr(test.id()),
         repr(test))
Esempio n. 21
0
 def test_shortDescription_is_id(self):
     # The shortDescription() of a PlaceHolder is the id, by default.
     test = PlaceHolder("test id")
     self.assertEqual(test.id(), test.shortDescription())
Esempio n. 22
0
 def test_shortDescription_specified(self):
     # If a shortDescription is provided to the constructor, then
     # shortDescription() returns that instead.
     test = PlaceHolder("test id", "description")
     self.assertEqual("description", test.shortDescription())
Esempio n. 23
0
                       '"name": "qux", '
                       '"task_level": [1]}\n')
        expected = ('{"timestamp": 1449835188.575052, '
                    '"task_uuid": "6c579710-1b95-4604-b5a1-36b56f8ceb53", '
                    '"message_type": "foo", '
                    '"name": "qux", '
                    '"task_level": [1]}')
        self.assertThat(_get_eliot_data(logged_line), Equals(expected))


identifier_characters = string.ascii_letters + string.digits + '_'
identifiers = text(average_size=20, min_size=1, alphabet=identifier_characters)
fqpns = lists(identifiers, min_size=1,
              average_size=5).map(lambda xs: '.'.join(xs))
tests = lists(identifiers, min_size=3,
              average_size=5).map(lambda xs: PlaceHolder('.'.join(xs)))


class MakeTemporaryTests(TesttoolsTestCase):
    """
    Tests for code for making temporary files and directories for tests.
    """
    @given(test_id=fqpns, max_length=integers(min_value=1, max_value=64))
    def test_directory_for_test(self, test_id, max_length):
        """
        _path_for_test_id returns a relative path of $module/$class/$method for
        the given test id.
        """
        assume(test_id.count('.') > 1)
        path = _path_for_test_id(test_id, max_length)
        self.expectThat(path, Not(StartsWith('/')))
Esempio n. 24
0
 def test_repr_just_id(self):
     # repr(placeholder) shows you how the object was constructed.
     test = PlaceHolder("test id")
     self.assertEqual(
         "<testtools.testcase.PlaceHolder(%s)>" % repr(test.id()),
         repr(test))
Esempio n. 25
0
 def test_shortDescription_specified(self):
     # If a shortDescription is provided to the constructor, then
     # shortDescription() returns that instead.
     test = PlaceHolder("test id", "description")
     self.assertEqual("description", test.shortDescription())
Esempio n. 26
0
 def test_repr_custom_outcome(self):
     test = PlaceHolder("test id", outcome='addSkip')
     self.assertEqual(
         "<testtools.testcase.PlaceHolder('addSkip', %r, {})>" % (
         test.id()), repr(test))
Esempio n. 27
0
 def test_supplies_details(self):
     details = {"quux": None}
     test = PlaceHolder("foo", details=details)
     result = ExtendedTestResult()
     test.run(result)
     self.assertEqual([("startTest", test), ("addSuccess", test, details), ("stopTest", test)], result._events)
Esempio n. 28
0
 def test_repr_custom_outcome(self):
     test = PlaceHolder("test id", outcome='addSkip')
     self.assertEqual(
         "<testtools.testcase.PlaceHolder('addSkip', %r, {})>" % (
         test.id()), repr(test))