Example #1
0
def validate_run(suite, run_result, expect_interruption):
    if expect_interruption or not run_result.session.results.is_success(allow_skips=True):
        assert run_result.exit_code != 0, 'slash run unexpectedly returned 0'
    else:
        assert run_result.exit_code == 0

    for test, results in iteritems(_group_results_by_test_id(suite, run_result)):
        _validate_single_test(test, results)
Example #2
0
def local_conf_dir(tmpdir, expected_dict):
    returned = tmpdir
    for i, (key, value) in enumerate(iteritems(expected_dict)):
        returned = returned.join('subdir{0}'.format(i))
        returned.mkdir()

        with returned.join('slashconf.py').open('w') as f:
            f.write('{0} = [{1!r}]'.format(key, value))
    return returned
Example #3
0
def local_conf_dir(tmpdir, expected_dict):
    returned = tmpdir
    for i, (key, value) in enumerate(iteritems(expected_dict)):
        returned = returned.join('subdir{}'.format(i))
        returned.mkdir()

        with returned.join('slashconf.py').open('w') as f:
            f.write('{} = [{!r}]'.format(key, value))
    return returned
Example #4
0
def test_cartesian_dict():

    params = {
        'a': [1, 2, 3],
        'b': [4, 5],
        'c': [6, 7],
    }

    assert set(frozenset(iteritems(x)) for x in iter_cartesian_dicts(params)) == \
        set(frozenset([('a', a_value), ('b', b_value), ('c', c_value)])
            for a_value, b_value, c_value in itertools.product(params['a'], params['b'], params['c']))
Example #5
0
def test_cartesian_dict():

    params = {
        'a': [1, 2, 3],
        'b': [4, 5],
        'c': [6, 7],
    }

    assert set(frozenset(iteritems(x)) for x in iter_cartesian_dicts(params)) == \
        set(frozenset([('a', a_value), ('b', b_value), ('c', c_value)])
            for a_value, b_value, c_value in itertools.product(params['a'], params['b'], params['c']))
Example #6
0
 def write_test_directory(self, structure, root):
     if not os.path.isdir(root):
         os.makedirs(root)
     for filename, item in iteritems(structure):
         path = os.path.join(root, filename)
         if isinstance(item, dict):
             self.write_test_directory(item, path)
         else:
             contents = self._get_test_item_contents(item)
             with open(path, "w") as f:
                 f.write(contents)
     return root
def _increment_scope(prev_scopes, **increments):
    if not prev_scopes:
        returned = {}
    else:
        returned = prev_scopes.copy()
    for key, value in iteritems(increments):
        if value == 0:
            continue
        if key not in returned:
            returned[key] = 0
        returned[key] += value
    return returned
Example #8
0
 def testing_scope(self, scope):
     self._fixture_store.push_scope(scope)
     yield
     self._fixture_store.pop_scope(scope)
     scope_id = get_scope_by_name(scope)
     for fixture_name, fixture in iteritems(self._fixtures):
         if fixture.__slash_fixture__.scope <= scope_id:
             if fixture_name in self._values:
                 assert fixture_name in self._cleanups_made
                 self._cleanups_made.remove(fixture_name)
                 self._values.pop(fixture_name)
     assert not self._cleanups_made, 'Unknown cleanups called'
Example #9
0
def test_local_conf_loading_multiple_times(local_conf_dir, expected_dict):
    items = list(iteritems(expected_dict))
    local_conf = LocalConfig()

    local_conf.push_path(str(local_conf_dir.join('..')))
    var_name, var_value = items[0]
    var = local_conf.get_dict()[var_name]
    assert var == [var_value]

    local_conf.push_path(str(local_conf_dir))

    assert var is local_conf.get_dict()[var_name]
Example #10
0
def _increment_scope(prev_scopes, **increments):
    if not prev_scopes:
        returned = {}
    else:
        returned = prev_scopes.copy()
    for key, value in iteritems(increments):
        if value == 0:
            continue
        if key not in returned:
            returned[key] = 0
        returned[key] += value
    return returned
Example #11
0
def test_local_conf_loading_multiple_times(local_conf_dir, expected_dict):
    items = list(iteritems(expected_dict))
    local_conf = LocalConfig()

    local_conf.push_path(str(local_conf_dir.join('..')))
    var_name, var_value = items[0]
    var = local_conf.get_dict()[var_name]
    assert var == [var_value]

    local_conf.push_path(str(local_conf_dir))

    assert var is local_conf.get_dict()[var_name]
Example #12
0
 def testing_scope(self, scope):
     self._fixture_store.push_scope(scope)
     yield
     self._fixture_store.pop_scope(scope, in_failure=False, in_interruption=False)
     scope_id = get_scope_by_name(scope)
     for fixture_name, fixture in iteritems(self._fixtures):
         if fixture.__slash_fixture__.scope <= scope_id:
             if fixture_name in self._values:
                 assert fixture_name in self._cleanups_made
                 self._cleanups_made.remove(fixture_name)
                 self._values.pop(fixture_name)
     assert not self._cleanups_made, 'Unknown cleanups called'
Example #13
0
 def write_test_directory(self, structure, root=None):
     if root is None:
         root = mkdtemp()
     if not os.path.isdir(root):
         os.makedirs(root)
     for filename, item in iteritems(structure):
         path = os.path.join(root, filename)
         if isinstance(item, dict):
             self.write_test_directory(item, path)
         else:
             contents = self._get_test_item_contents(item)
             with open(path, "w") as f:
                 f.write(contents)
     return root
Example #14
0
def validate_run(suite, run_result, expect_interruption,
                 expect_session_errors):
    if expect_interruption or not run_result.session.results.is_success(
            allow_skips=True):
        assert run_result.exit_code != 0, '`slash run` unexpectedly returned 0'
    else:
        assert run_result.exit_code == 0, '`slash run` unexpectedly returned {}. Output: {}'.format(
            run_result.exit_code, run_result.get_console_output())

    global_result = run_result.session.results.global_result
    errors = global_result.get_errors() + global_result.get_failures()
    if expect_session_errors:
        assert errors, 'Expected session errors but found none'
    else:
        assert not errors, 'Sessions errors were not expected (Got {})'.format(
            errors)

    for test, results in iteritems(_group_results_by_test_id(
            suite, run_result)):
        _validate_single_test(test, results)
Example #15
0
def _group_results_by_test_id(suite, run_result):
    tests_by_id = dict((t.id, t) for t in suite)
    unseen = tests_by_id.copy()

    groups = {}

    for result in run_result.session.results:
        if 'Interactive' ==  result.test_metadata.address:
            continue
        test_id = get_test_id_from_test_address(result.test_metadata.address)
        assert tests_by_id[test_id].is_selected()
        groups.setdefault(tests_by_id[test_id], []).append(result)
        unseen.pop(test_id, None)

    for test_id, test in list(iteritems(unseen)):
        if not test.is_selected():
            unseen.pop(test_id, None)

    assert not unseen, 'Expected results not found ({0})'.format(unseen)

    return groups
Example #16
0
def test_iter_fixture_variations_parametrized(suite, planned_test):
    """ Test iteration with no fixture parametrization"""
    fixtures = [planned_test.add_fixture(suite.add_fixture())
                for i in range(2)]

    for fixture in fixtures:
        for i in range(2):
            fixture.parametrize()

    # for each fixture, the possible param dicts it can yield (as lists)
    param_dicts_ordered_by_fixture = []
    for fixture in fixtures:
        fixture_param_dicts = []
        param_names = []
        param_value_options = []
        for param_name, options in iteritems(fixture.params):
            param_names.append(param_name)
            param_value_options.append(options)

        for combination in itertools.product(*itervalues(fixture.params)):
            fixture_param_dicts.append(dict(zip(fixture.params, combination)))

        param_dicts_ordered_by_fixture.append(fixture_param_dicts)


    expected = [dict((f.name, {'value': f.value, 'params': param_dict})
                     for f, param_dict in zip(fixtures, dict_combination))
                for dict_combination in itertools.product(*param_dicts_ordered_by_fixture)]

    got = list(planned_test.iter_expected_fixture_variations())

    assert len(expected) == len(got)

    # we can't use sets here, and sorting the two lists is a nightmare in Python 3 since they contain dicts
    for expected_dict in expected:
        got.remove(expected_dict)
    assert not got
Example #17
0
def test_local_conf(local_conf, expected_dict):
    conf = local_conf.get_dict()
    for key, value in iteritems(expected_dict):
        assert [value] == conf[key]
Example #18
0
def test_local_conf(local_conf, expected_dict):
    conf = local_conf.get_dict()
    for key, value in iteritems(expected_dict):
        assert [value] == conf[key]