• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2# Copyright 2016 the V8 project authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6import itertools
7import os
8import sys
9import tempfile
10import unittest
11
12# Needed because the test runner contains relative imports.
13TOOLS_PATH = os.path.dirname(
14    os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
15sys.path.append(TOOLS_PATH)
16
17from testrunner.local.testsuite import TestSuite, TestGenerator
18from testrunner.objects.testcase import TestCase
19from testrunner.test_config import TestConfig
20
21
22class TestSuiteTest(unittest.TestCase):
23
24  def setUp(self):
25    test_dir = os.path.dirname(__file__)
26    self.test_root = os.path.join(test_dir, "fake_testsuite")
27    self.test_config = TestConfig(
28        command_prefix=[],
29        extra_flags=[],
30        isolates=False,
31        mode_flags=[],
32        no_harness=False,
33        noi18n=False,
34        random_seed=0,
35        run_skipped=False,
36        shell_dir='fake_testsuite/fake_d8',
37        timeout=10,
38        verbose=False,
39    )
40
41    self.suite = TestSuite.Load(self.test_root, self.test_config,
42                                "standard_runner")
43
44  def testLoadingTestSuites(self):
45    self.assertEquals(self.suite.name, "fake_testsuite")
46    self.assertEquals(self.suite.test_config, self.test_config)
47
48    # Verify that the components of the TestSuite aren't loaded yet.
49    self.assertIsNone(self.suite.tests)
50    self.assertIsNone(self.suite.statusfile)
51
52  def testLoadingTestsFromDisk(self):
53    tests = self.suite.load_tests_from_disk(statusfile_variables={})
54
55    def is_generator(iterator):
56      return iterator == iter(iterator)
57
58    self.assertTrue(is_generator(tests))
59    self.assertEquals(tests.test_count_estimate, 2)
60
61    slow_tests, fast_tests = list(tests.slow_tests), list(tests.fast_tests)
62    # Verify that the components of the TestSuite are loaded.
63    self.assertTrue(len(slow_tests) == len(fast_tests) == 1)
64    self.assertTrue(all(test.is_slow for test in slow_tests))
65    self.assertFalse(any(test.is_slow for test in fast_tests))
66    self.assertIsNotNone(self.suite.statusfile)
67
68  def testMergingTestGenerators(self):
69    tests = self.suite.load_tests_from_disk(statusfile_variables={})
70    more_tests = self.suite.load_tests_from_disk(statusfile_variables={})
71
72    # Merge the test generators
73    tests.merge(more_tests)
74    self.assertEquals(tests.test_count_estimate, 4)
75
76    # Check the tests are sorted by speed
77    test_speeds = []
78    for test in tests:
79      test_speeds.append(test.is_slow)
80
81    self.assertEquals(test_speeds, [True, True, False, False])
82
83
84if __name__ == '__main__':
85  unittest.main()
86