Beispiel #1
0
 def test_ids_are_unique(self):
     ids = []
     for _ in range(2):
         with Session() as session:
             ids.append(session.id)
             ids.append(session.id_space.allocate())
     self.assertEquals(len(ids), len(set(ids)), "IDs are not unique")
Beispiel #2
0
    def setUp(self):
        super(SessionResultTest, self).setUp()
        self.results = [
            Result() for _ in range(10)
        ]
        for r in self.results:
            r.mark_started()
        # one result with both errors and failures
        try:
            1 / 0
        except:
            self.results[1].add_error()
            self.results[1].add_failure()
            # one result with failure
            self.results[2].add_failure()
            # one result with error
            self.results[3].add_error()
            self.results[5].add_error()

        # one result will skip
        self.results[4].add_skip("Reason")

        # and one result will skip with error
        self.results[5].add_skip("Reason")
        num_finished = 7

        for result in self.results[:num_finished]:
            result.mark_finished()
        self.result = SessionResults(Session())
        for index, r in enumerate(self.results):
            self.result._results_dict[index] = r  # pylint: disable=protected-access
Beispiel #3
0
def test_parallel_mode_activation_causes_warning(config_override, checkpoint,
                                                 is_parallel_mode):
    @slash.plugins.parallel_mode(parallel_utils.ParallelPluginModes.DISABLED)
    class Plugin(slash.plugins.PluginInterface):
        def session_start(self):
            checkpoint()

        def get_name(self):
            return type(self).__name__.lower()

    if is_parallel_mode:
        config_override("parallel.num_workers", 1)
        assert parallel_utils.is_parallel_session()
    plugin = Plugin()
    assert try_get_mark(
        plugin, 'parallel_mode') == parallel_utils.ParallelPluginModes.DISABLED
    with Session():
        slash.plugins.manager.install(plugin)
        slash.plugins.manager.activate(plugin)
        slash.hooks.session_start()  # pylint: disable=no-member

        warning_message_expected = "Activating plugin {} though it's configuration for parallel mode doesn't fit to current session"\
                                    .format(plugin.get_name())
        is_warning_appeared = warning_message_expected in [
            warning.message for warning in slash.session.warnings
        ]
        assert is_warning_appeared if is_parallel_mode else not is_warning_appeared
        assert checkpoint.called
Beispiel #4
0
def test_total_num_tests(suite):
    suite.debug_info = False

    path = suite.commit()

    with Session() as s:
        Loader().get_runnables(path)
        assert s.get_total_num_tests() == len(suite)
Beispiel #5
0
def test_loader_skips_empty_dirs(tmpdir):
    tests_dir = tmpdir.join('tests')
    with tests_dir.join('.dir').join('test_something.py').open(
            'w', ensure=True) as f:
        f.write('def test_something():\n    pass')

    with Session():
        runnables = Loader().get_runnables(str(tests_dir))

    assert runnables == []
Beispiel #6
0
def test_session_adds_simple_filter(request):
    @request.addfinalizer
    def cleanup():  # pylint: disable=unused-variable
        warnings.simplefilter('default')

    warnings.simplefilter('ignore')
    with Session() as s:
        warnings.warn('bla')

    assert len(s.warnings.warnings) == 1
Beispiel #7
0
def test_children_not_connected_timeout(runnable_test_dir, config_override):
    config_override("parallel.worker_connect_timeout", 0)
    config_override("parallel.num_workers", 1)
    with Session():
        runnables = Loader().get_runnables(str(runnable_test_dir))
        parallel_manager = ParallelManager([])
        parallel_manager.start_server_in_thread(runnables)
        time.sleep(0.1)
        with slash.assert_raises(ParallelTimeout) as caught:
            parallel_manager.wait_all_workers_to_connect()
        assert caught.exception.args[0] == 'Not all clients connected'
Beispiel #8
0
def test_timeout_no_request_to_server(config_override, runnable_test_dir):
    config_override("parallel.no_request_timeout", 1)
    with Session():
        runnables = Loader().get_runnables(str(runnable_test_dir))
        parallel_manager = ParallelManager([])
        parallel_manager.start_server_in_thread(runnables)
        parallel_manager.server.state = ServerStates.SERVE_TESTS

        with slash.assert_raises(ParallelTimeout) as caught:
            parallel_manager.start()
        assert 'No request sent to server' in caught.exception.args[0]
Beispiel #9
0
def test_session_warning_calls_hook():
    notified = []

    @slash.hooks.warning_added.register  # pylint: disable=no-member
    def warning_added(warning):  # pylint: disable=unused-variable
        notified.append(warning)

    with Session() as session:
        warnings.warn('bla')

    assert list(session.warnings) == notified != []
Beispiel #10
0
def test_loader_warns_duplicate_test_funcs(tmpdir):
    tests_dir = tmpdir.join('tests')
    full_path = tests_dir.join('.dir').join('test_something.py')
    test_name = 'test_something'
    with full_path.open('w', ensure=True) as f:
        f.write('def {0}():\n    assert True\n'.format(test_name))
        f.write('def {0}():\n    assert True\n'.format(test_name))
    with Session() as session:
        Loader().get_runnables([str(full_path)])
        assert len(session.warnings) == 1
        assert 'Duplicate' in session.warnings.warnings[0].details['message']
        assert test_name in session.warnings.warnings[0].details['message']
Beispiel #11
0
def test_loader_sort_filenames(tmpdir):

    tests_dir = tmpdir.join(str(uuid4()))

    filenames = []

    for _ in range(10):
        filename = str(uuid4()).replace('-', '') + '.py'

        with tests_dir.join(filename).open('w', ensure=True) as f:
            f.write('def test_something():\n    pass')

        filenames.append(filename)

    with Session():
        runnables = Loader().get_runnables(str(tests_dir))

    assert [
        os.path.basename(runnable.__slash__.file_path)
        for runnable in runnables
    ] == sorted(filenames)
Beispiel #12
0
def test_session_context_result():
    with Session() as s:
        assert context.session is s
        assert context.result is s.results.global_result
Beispiel #13
0
def test_globals_dir():
    with Session():
        assert 'x' not in dir(slash.g)
        slash.g.x = 2
        assert 'x' in dir(slash.g)
Beispiel #14
0
def test_get_current_session():
    with Session() as s:
        assert context.session is s
        assert context.session is not slash.session
        assert s == slash.session