Пример #1
0
 def test_options_adds_options(self):
     select = SelectBucket()
     parser = OptionParser()
     select.options(parser=parser, env={})
     self.assertThat(
         parser.option_list[-2:],
         MatchesListwise(
             [
                 # The --with-select-bucket option.
                 MatchesStructure.byEquality(
                     action="store_true",
                     default=None,
                     dest="enable_plugin_select_bucket",
                 ),
                 # The --select-bucket option.
                 MatchesStructure.byEquality(
                     action="callback",
                     default=None,
                     dest="select-bucket_selected_bucket",
                     metavar="BUCKET/BUCKETS",
                     type="string",
                     _short_opts=[],
                     _long_opts=["--select-bucket"],
                 ),
             ]
         ),
     )
Пример #2
0
 def test_prepareTestRunner_does_nothing_when_no_bucket_selected(self):
     select = SelectBucket()
     parser = OptionParser()
     select.add_options(parser=parser, env={})
     options, rest = parser.parse_args(["--with-select-bucket"])
     select.configure(options, sentinel.conf)
     self.assertThat(select.prepareTestRunner(sentinel.runner), Is(None))
Пример #3
0
    def test_prepareTestRunner_wraps_given_runner_and_filters_tests(self):
        select = SelectBucket()
        parser = OptionParser()
        select.add_options(parser=parser, env={})
        options, rest = parser.parse_args(
            ["--with-select-bucket", "--select-bucket", "8/13"]
        )
        select.configure(options, sentinel.conf)

        # We start at 65 because chr(65) is "A" and so makes a nice readable
        # ID for the test. We end at 77 because chr(77) is "M", a readable ID
        # once again, but more importantly it means we'll have 13 tests, which
        # is the modulus we started with.
        tests = map(self._make_test_with_id, map(chr, range(65, 78)))
        test = unittest.TestSuite(tests)
        self.assertThat(test.countTestCases(), Equals(13))

        class MockTestRunner:
            def run(self, test):
                self.test = test

        runner = runner_orig = MockTestRunner()
        runner = select.prepareTestRunner(runner)
        self.assertThat(runner, IsInstance(noseplug.SelectiveTestRunner))

        runner.run(test)

        self.assertThat(runner_orig.test, IsInstance(type(test)))
        self.assertThat(runner_orig.test.countTestCases(), Equals(1))
        # Note how the test with ID of "H" is the only one selected.
        self.assertThat({t.id() for t in runner_orig.test}, Equals({"H"}))
        self.assertThat(ord("H") % 13, Equals(7))
Пример #4
0
 def test__configure_parses_selected_bucket(self):
     select = SelectBucket()
     parser = OptionParser()
     select.add_options(parser=parser, env={})
     options, rest = parser.parse_args(
         ["--with-select-bucket", "--select-bucket", "8/13"])
     select.configure(options, sentinel.conf)
     self.assertThat(select, MatchesStructure(_selectTest=IsCallable()))