コード例 #1
0
 def test_load_list_passes_ids(self):
     list_file = tempfile.NamedTemporaryFile()
     self.addCleanup(list_file.close)
     expected_ids = set(['foo', 'quux', 'bar'])
     write_list(list_file, expected_ids)
     list_file.flush()
     ui, cmd = self.get_test_ui_and_cmd(options=[('load_list',
                                                  list_file.name)])
     cmd.repository_factory = memory.RepositoryFactory()
     self.setup_repo(cmd, ui)
     self.set_config(
         '[DEFAULT]\ntest_command=foo $IDOPTION\ntest_id_option=--load-list $IDFILE\n'
     )
     params, capture_ids = self.capture_ids()
     self.useFixture(
         MonkeyPatch(
             'testrepository.testcommand.TestCommand.get_run_command',
             capture_ids))
     cmd_result = cmd.execute()
     self.assertEqual(
         [('results', Wildcard),
          ('summary', True, 0, -3, None, None, [('id', 1, None)])],
         ui.outputs)
     self.assertEqual(0, cmd_result)
     self.assertEqual([[Wildcard, expected_ids, [], None]], params)
コード例 #2
0
ファイル: test_run.py プロジェクト: dstanek/testrepository
 def test_load_list_failing_takes_id_intersection(self):
     list_file = tempfile.NamedTemporaryFile()
     self.addCleanup(list_file.close)
     write_list(list_file, ['foo', 'quux', 'failing1'])
     # The extra tests - foo, quux - won't match known failures, and the
     # unlisted failure failing2 won't match the list.
     expected_ids = set(['failing1'])
     list_file.flush()
     ui, cmd = self.get_test_ui_and_cmd(
         options=[('load_list', list_file.name), ('failing', True)])
     cmd.repository_factory = memory.RepositoryFactory()
     self.setup_repo(cmd, ui)
     self.set_config(
         '[DEFAULT]\ntest_command=foo $IDOPTION\ntest_id_option=--load-list $IDFILE\n')
     params, capture_ids = self.capture_ids()
     self.useFixture(MonkeyPatch(
         'testrepository.testcommand.TestCommand.get_run_command',
         capture_ids))
     cmd_result = cmd.execute()
     self.assertEqual([
         ('results', Wildcard),
         ('summary', True, 0, -3, None, None, [('id', 1, None)])
         ], ui.outputs)
     self.assertEqual(0, cmd_result)
     self.assertEqual([[Wildcard, expected_ids, [], None]], params)
コード例 #3
0
 def make_listfile(self):
     name = None
     try:
         if self._listpath:
             name = self._listpath
             stream = open(name, 'wb')
         else:
             fd, name = tempfile.mkstemp()
             stream = os.fdopen(fd, 'wb')
         self.list_file_name = name
         write_list(stream, self.test_ids)
         stream.close()
     except:
         if name:
             os.unlink(name)
         raise
     self.addCleanup(os.unlink, name)
     return name
コード例 #4
0
 def make_listfile(self):
     name = None
     try:
         if self._listpath:
             name = self._listpath
             stream = open(name, 'wb')
         else:
             fd, name = tempfile.mkstemp()
             stream = os.fdopen(fd, 'wb')
         self.list_file_name = name
         write_list(stream, self.test_ids)
         stream.close()
     except:
         if name:
             os.unlink(name)
         raise
     self.addCleanup(os.unlink, name)
     return name
コード例 #5
0
def main():
    parser = argparse.ArgumentParser(
        description="Test runner that supports both Python 2 and Python 3.")

    parser.add_argument("--load-list",
                        metavar="PATH",
                        help="Path to read list of tests to run from.",
                        type=str)
    parser.add_argument("--list",
                        help="List available tests.",
                        action="store_true")

    args = parser.parse_args()

    if args.list:
        testids = []
        output = subprocess.check_output(
            ['python2', './brz', 'selftest', '--subunit2', '--list'])
        for n in parse_enumeration(output):
            testids.append('python2.' + n)

        output = subprocess.check_output(
            ['python3', './brz', 'selftest', '--subunit2', '--list'])
        for n in parse_enumeration(output):
            testids.append('python3.' + n)
        stream = StreamResultToBytes(sys.stdout)
        for testid in testids:
            stream.status(test_id=testid, test_status='exists')
    else:
        if args.load_list:
            py2_tests = []
            py3_tests = []
            with open(args.load_list, 'r') as f:
                all_tests = parse_list(f.read())
            for testname in all_tests:
                if testname.startswith("python2."):
                    py2_tests.append(testname[len('python2.'):].strip())
                elif testname.startswith("python3."):
                    py3_tests.append(testname[len('python3.'):].strip())
                else:
                    sys.stderr.write("unknown prefix %s\n" % testname)
            if py2_tests:
                with tempfile.NamedTemporaryFile() as py2f:
                    write_list(py2f, py2_tests)
                    py2f.flush()
                    subprocess.call(
                        'python2 ./brz selftest --subunit2 --load-list=%s | subunit-filter -s --passthrough --rename "^" "python2."'
                        % py2f.name,
                        shell=True)

            if py3_tests:
                with tempfile.NamedTemporaryFile() as py3f:
                    write_list(py3f, py3_tests)
                    py3f.flush()
                    subprocess.call(
                        'python3 ./brz selftest --subunit2 --load-list=%s | subunit-filter -s --passthrough --rename "^" "python3."'
                        % py3f.name,
                        shell=True)
        else:
            subprocess.call(
                'python2 ./brz selftest --subunit2 | subunit-filter -s --passthrough --rename "^" "python2."',
                shell=True)
            subprocess.call(
                'python3 ./brz selftest --subunit2 | subunit-filter -s --passthrough --rename "^" "python3."',
                shell=True)