def test_matrix_expand_include(): conf = config.Config() conf.environment_type = 'something' conf.pythons = ["2.6"] conf.matrix = {'a': '1'} conf.include = [ {'python': '3.5', 'b': '2'}, {'sys_platform': sys.platform, 'python': '2.7', 'b': '3'}, {'sys_platform': sys.platform + 'nope', 'python': '2.7', 'b': '3'}, {'environment_type': 'nope', 'python': '2.7', 'b': '4'}, {'environment_type': 'something', 'python': '2.7', 'b': '5'}, ] combinations = _sorted_dict_list(environment.iter_matrix( conf.environment_type, conf.pythons, conf)) expected = _sorted_dict_list([ {('python', None): '2.6', ('req', 'a'): '1'}, {('python', None): '3.5', ('req', 'b'): '2'}, {('python', None): '2.7', ('req', 'b'): '3'}, {('python', None): '2.7', ('req', 'b'): '5'} ]) assert combinations == expected conf.include = [ {'b': '2'} ] with pytest.raises(util.UserError): list(environment.iter_matrix(conf.environment_type, conf.pythons, conf))
def test_iter_env_matrix_combinations(): conf = config.Config() conf.environment_type = 'something' conf.pythons = ["2.6"] conf.matrix = {} conf.include = [] # (matrix, expected) env_matrices = [ ({'var0': ['val0', 'val1'], 'var1': ['val2', 'val3']}, [{'var0': 'val0', 'var1': 'val2'}, {'var0': 'val0', 'var1': 'val3'}, {'var0': 'val1', 'var1': 'val2'}, {'var0': 'val1', 'var1': 'val3'}]), ({'var0': ['val0', 'val1'], 'var1': ['val2', None]}, [{'var0': 'val0', 'var1': 'val2'}, {'var0': 'val0'}, {'var0': 'val1', 'var1': 'val2'}, {'var0': 'val1'}]), ({'var0': ['val0', 'val1']}, [{'var0': 'val0'}, {'var0': 'val1'}]), ({}, [{}]), ] for matrix, expected in env_matrices: conf.matrix = {'env': matrix} expected = [{('env', key): value for key, value in item.items()} for item in expected] for m in expected: m['python', None] = "2.6" result = _sorted_dict_list(environment.iter_matrix(conf.environment_type, conf.pythons, conf)) assert result == _sorted_dict_list(expected)
def test_matrix_expand_basic(): conf = config.Config() conf.environment_type = 'something' conf.pythons = ["2.6", "2.7"] conf.matrix = { 'pkg1': None, 'pkg2': '', 'pkg3': [''], 'pkg4': ['1.2', '3.4'], 'pkg5': [] } combinations = _sorted_dict_list(environment.iter_matrix( conf.environment_type, conf.pythons, conf)) expected = _sorted_dict_list([ {('python', None): '2.6', ('req', 'pkg2'): '', ('req', 'pkg3'): '', ('req', 'pkg4'): '1.2', ('req', 'pkg5'): ''}, {('python', None): '2.6', ('req', 'pkg2'): '', ('req', 'pkg3'): '', ('req', 'pkg4'): '3.4', ('req', 'pkg5'): ''}, {('python', None): '2.7', ('req', 'pkg2'): '', ('req', 'pkg3'): '', ('req', 'pkg4'): '1.2', ('req', 'pkg5'): ''}, {('python', None): '2.7', ('req', 'pkg2'): '', ('req', 'pkg3'): '', ('req', 'pkg4'): '3.4', ('req', 'pkg5'): ''}, ]) assert combinations == expected
def test_matrix_expand_include_detect_env_type(): conf = config.Config() conf.environment_type = None conf.pythons = [PYTHON_VER1] conf.matrix = {} conf.exclude = [{}] conf.include = [ {'sys_platform': sys.platform, 'python': PYTHON_VER1}, ] combinations = _sorted_dict_list(environment.iter_matrix( conf.environment_type, conf.pythons, conf)) expected = _sorted_dict_list([ {('python', None): PYTHON_VER1}, ]) assert combinations == expected
def test_matrix_expand_exclude(): conf = config.Config() conf.environment_type = 'something' conf.pythons = ["2.6", "2.7"] conf.matrix = {'a': '1', 'b': ['1', None]} conf.include = [{'python': '2.7', 'b': '2', 'c': None}] # check basics conf.exclude = [ { 'python': '2.7', 'b': '2' }, { 'python': '2.7', 'b': None }, { 'python': '2.6', 'a': '1' }, ] combinations = _sorted_dict_list( environment.iter_matrix(conf.environment_type, conf.pythons, conf)) expected = _sorted_dict_list([{ ('python', None): '2.7', ('req', 'a'): '1', ('req', 'b'): '1' }, { ('python', None): '2.7', ('req', 'b'): '2' }]) assert combinations == expected # check regexp conf.exclude = [ { 'python': '.*', 'b': None }, ] combinations = _sorted_dict_list( environment.iter_matrix(conf.environment_type, conf.pythons, conf)) expected = _sorted_dict_list([{ ('python', None): '2.6', ('req', 'a'): '1', ('req', 'b'): '1' }, { ('python', None): '2.7', ('req', 'a'): '1', ('req', 'b'): '1' }, { ('python', None): '2.7', ('req', 'b'): '2' }]) assert combinations == expected # check environment_type as key conf.exclude = [ { 'environment_type': 'some.*' }, ] combinations = _sorted_dict_list( environment.iter_matrix(conf.environment_type, conf.pythons, conf)) expected = [{('python', None): '2.7', ('req', 'b'): '2'}] assert combinations == expected # check sys_platform as key conf.exclude = [ { 'sys_platform': sys.platform }, ] combinations = _sorted_dict_list( environment.iter_matrix(conf.environment_type, conf.pythons, conf)) expected = [{('python', None): '2.7', ('req', 'b'): '2'}] assert combinations == expected # check inverted regex conf.exclude = [{'python': '(?!2.6).*'}] combinations = _sorted_dict_list( environment.iter_matrix(conf.environment_type, conf.pythons, conf)) expected = _sorted_dict_list([{ ('python', None): '2.6', ('req', 'a'): '1', ('req', 'b'): '1' }, { ('python', None): '2.6', ('req', 'a'): '1' }, { ('python', None): '2.7', ('req', 'b'): '2' }]) assert combinations == expected