How to use something_else method in Testify

Best Python code snippet using Testify_python

test_multispec.py

Source:test_multispec.py Github

copy

Full Screen

1import os2import pytest3import yaml4from distgen.multispec import Multispec, MultispecError5here = os.path.dirname(__file__)6fixtures = os.path.join(here, 'fixtures')7ms_fixtures = os.path.join(fixtures, 'multispec')8simplest = {'version': '1',9 'specs': {'distroinfo': {'fedora': {'distros': ['fedora-26-x86_64']}}}10 }11class TestMultispec(object):12 @pytest.mark.parametrize('proj_dir, path', [13 (ms_fixtures, 'simplest.yaml'),14 (fixtures, os.path.join('multispec', 'simplest.yaml')),15 ])16 def test_from_path_ok(self, proj_dir, path):17 assert Multispec.from_path(proj_dir, path).raw_data == simplest18 def test_from_path_nok(self):19 with pytest.raises(SystemExit):20 Multispec.from_path('.', 'nope')21 def test_validate(self):22 with open(os.path.join(ms_fixtures, 'complex.yaml')) as f:23 Multispec(yaml.load(f, Loader=yaml.SafeLoader))._validate()24 def test_has_spec_group(self):25 ms = Multispec.from_path(ms_fixtures, 'complex.yaml')26 assert ms.has_spec_group('something_else')27 assert not ms.has_spec_group('nope')28 def test_get_spec_group(self):29 ms = Multispec.from_path(ms_fixtures, 'complex.yaml')30 assert ms.get_spec_group('version') == \31 {'2.2': {'version': '2.2'}, '2.4': {'version': '2.4'}}32 with pytest.raises(KeyError):33 ms.get_spec_group('nope')34 def test_has_spec_group_item(self):35 ms = Multispec.from_path(ms_fixtures, 'complex.yaml')36 assert ms.has_spec_group_item('something_else', 'foo')37 assert not ms.has_spec_group_item('something_else', 'nope')38 def test_get_spec_group_item(self):39 ms = Multispec.from_path(ms_fixtures, 'complex.yaml')40 assert ms.get_spec_group_item('something_else', 'foo') == {'spam': 'ham'}41 with pytest.raises(KeyError):42 ms.get_spec_group_item('something_else', 'nope')43 def test_get_all_combinations_simple(self):44 ms = Multispec.from_path(ms_fixtures, 'simplest.yaml')45 assert list(ms.get_all_combinations()) == [{'distro': 'fedora-26-x86_64.yaml'}]46 def test_get_all_combinations_complex(self):47 ms = Multispec.from_path(ms_fixtures, 'complex.yaml')48 def comb_key(c):49 return (c['distro'], c['something_else'], c['version'])50 assert sorted(ms.get_all_combinations(), key=comb_key) == sorted([51 {'distro': 'centos-7-x86_64.yaml', 'something_else': 'bar', 'version': '2.2'},52 {'distro': 'centos-7-x86_64.yaml', 'something_else': 'bar', 'version': '2.4'},53 {'distro': 'centos-7-x86_64.yaml', 'something_else': 'foo', 'version': '2.2'},54 {'distro': 'centos-7-x86_64.yaml', 'something_else': 'foo', 'version': '2.4'},55 {'distro': 'centos-7-x86_64.yaml', 'something_else': 'baz', 'version': '2.2'},56 {'distro': 'centos-7-x86_64.yaml', 'something_else': 'baz', 'version': '2.4'},57 {'distro': 'fedora-26-x86_64.yaml', 'something_else': 'bar', 'version': '2.2'},58 {'distro': 'fedora-26-x86_64.yaml', 'something_else': 'bar', 'version': '2.4'},59 {'distro': 'fedora-26-x86_64.yaml', 'something_else': 'foo', 'version': '2.4'},60 {'distro': 'fedora-26-x86_64.yaml', 'something_else': 'baz', 'version': '2.2'},61 {'distro': 'fedora-26-x86_64.yaml', 'something_else': 'baz', 'version': '2.4'},62 {'distro': 'fedora-25-x86_64.yaml', 'something_else': 'bar', 'version': '2.2'},63 {'distro': 'fedora-25-x86_64.yaml', 'something_else': 'foo', 'version': '2.2'},64 {'distro': 'fedora-25-x86_64.yaml', 'something_else': 'foo', 'version': '2.4'},65 {'distro': 'fedora-25-x86_64.yaml', 'something_else': 'baz', 'version': '2.2'},66 {'distro': 'fedora-25-x86_64.yaml', 'something_else': 'baz', 'version': '2.4'},67 ], key=comb_key)68 def test_parse_selectors_ok(self):69 ms = Multispec.from_path(ms_fixtures, 'simplest.yaml')70 assert ms.parse_selectors(['foo=bar', 'spam=ham']) == {'foo': 'bar', 'spam': 'ham'}71 def test_parse_selectors_nok(self):72 ms = Multispec.from_path(ms_fixtures, 'simplest.yaml')73 with pytest.raises(MultispecError):74 ms.parse_selectors(['foo bar'])75 @pytest.mark.parametrize('node, distro, selectors, expected', [76 ('exclude', 'fedora-26-x86_64', ['version=2.2'], [True, False]),77 ('exclude', 'fedora-26-x86_64', ['version=2.4'], [False, False]),78 ('combination_extras', 'fedora-26-x86_64', ['version=2.4'],79 [{'name_label': "$FGC/$NAME",80 'base_version': 1}, False]),81 ('combination_extras', 'fedora-26-x86_64', ['version=2.2'],82 [False, False]),83 ('combination_extras', 'centos-7-x86_64', ['version=2.2'],84 [False, {'name_label': 'centos/SW-2.2-centos7'}]),85 ])86 def test_check_matrix_combinations(self, node, distro,87 selectors, expected):88 ms = Multispec.from_path(ms_fixtures, 'complex.yaml')89 parsed_selectors = ms.parse_selectors(selectors)90 assert list(ms.check_matrix_combinations(node,91 distro,92 parsed_selectors)) == expected93 def test_distrofile2name(self):94 ms = Multispec.from_path(ms_fixtures, 'simplest.yaml')95 assert ms.distrofile2name('foo/bar/fedora-26-x86_64.yaml') == 'fedora-26-x86_64'96 def test_verify_selectors_ok(self):97 ms = Multispec.from_path(ms_fixtures, 'complex.yaml')98 assert ms.verify_selectors(['version=2.4', 'something_else=foo'],99 distro='fedora-26-x86_64') == (True, '')100 @pytest.mark.parametrize('selectors, distro, msg', [101 (['distroinfo=fedora'], 'fedora-26-x86_64', '"distroinfo" not allowed in selectors, it is '102 'chosen automatically based on distro'),103 (['version=2.2'], 'fedora-26-x86_64', '"something_else" selector must be present'),104 (['xxx=asd'], 'fedora-26-x86_64', '"xxx" not an entry in specs'),105 (['version=3.4'], 'fedora-26-x86_64', '"3.4" not an entry in specs.version'),106 (['version=2.2', 'something_else=foo'], 'fedora-26-x86_64', 'This combination is excluded '107 'in matrix section'),108 (['version=2.4', 'something_else=foo'], 'fedora-27-x86_64', '"fedora-27-x86_64" distro '109 'not found in any specs.distroinfo.*.distros section'),110 ])111 def test_verify_selectors_nok(self, selectors, distro, msg):112 ms = Multispec.from_path(ms_fixtures, 'complex.yaml')113 assert ms.verify_selectors(selectors, distro) == (False, msg)114 def test_select_data_ok(self):115 ms = Multispec.from_path(ms_fixtures, 'complex.yaml')116 assert ms.select_data(['version=2.4', 'something_else=foo'], 'fedora-26-x86_64') == \117 {'authoritative_source_url': 'some.url.fedoraproject.org',118 'distro_specific_help': 'Some Fedora specific help',119 'spam': 'ham',120 'vendor': 'Fedora Project',121 'version': '2.4',122 'base_version': 1,123 'name_label': '$FGC/$NAME'}124 def test_select_data_nok(self):125 ms = Multispec.from_path(ms_fixtures, 'complex.yaml')126 with pytest.raises(MultispecError):...

Full Screen

Full Screen

test_scrub_none_parameters.py

Source:test_scrub_none_parameters.py Github

copy

Full Screen

1from __future__ import (absolute_import, division, print_function)2__metaclass__ = type3from ansible_collections.amazon.aws.plugins.module_utils.core import scrub_none_parameters4import pytest5scrub_none_test_data = [6 (dict(),7 dict()8 ),9 (dict(param1='something'),10 dict(param1='something')11 ),12 (dict(param1=False),13 dict(param1=False)14 ),15 (dict(param1='something', param2='something_else'),16 dict(param1='something', param2='something_else')17 ),18 (dict(param1='something', param2=dict()),19 dict(param1='something', param2=dict())20 ),21 (dict(param1='something', param2=None),22 dict(param1='something')23 ),24 (dict(param1='something', param2=None, param3=None),25 dict(param1='something')26 ),27 (dict(param1='something', param2=None, param3=None, param4='something_else'),28 dict(param1='something', param4='something_else')29 ),30 (dict(param1=dict(sub_param1='something', sub_param2=None), param2=None, param3=None, param4='something_else'),31 dict(param1=dict(sub_param1='something'), param4='something_else')32 ),33 (dict(param1=dict(sub_param1='something', sub_param2=dict(sub_sub_param1='another_thing')), param2=None, param3=None, param4='something_else'),34 dict(param1=dict(sub_param1='something', sub_param2=dict(sub_sub_param1='another_thing')), param4='something_else')35 ),36 (dict(param1=dict(sub_param1='something', sub_param2=dict()), param2=None, param3=None, param4='something_else'),37 dict(param1=dict(sub_param1='something', sub_param2=dict()), param4='something_else')38 ),39 (dict(param1=dict(sub_param1='something', sub_param2=False), param2=None, param3=None, param4='something_else'),40 dict(param1=dict(sub_param1='something', sub_param2=False), param4='something_else')41 ),42 (dict(param1=None, param2=None),43 dict()44 ),45 (dict(param1=None, param2=[]),46 dict(param2=[])47 )48]49@pytest.mark.parametrize("input_params, output_params", scrub_none_test_data)50def test_scrub_none_parameters(input_params, output_params):...

Full Screen

Full Screen

test_PT018_composite_assertion.py

Source:test_PT018_composite_assertion.py Github

copy

Full Screen

1import pytest2from flake8_plugin_utils.utils import assert_error, assert_not_error3from flake8_pytest_style.errors import CompositeAssertion4from flake8_pytest_style.visitors.assertion import AssertionVisitor5def test_ok():6 code = """7 def test_xxx():8 assert something9 assert something or something_else10 assert something or something_else and something_third11 assert not (something and something_else)12 """13 assert_not_error(AssertionVisitor, code)14@pytest.mark.parametrize(15 'condition',16 [17 'something and something_else',18 'something and something_else and something_third',19 'something and not something_else',20 'something and (something_else or something_third)',21 'not (something or something_else)',22 'not (something or something_else or something_third)',23 'not (something or something_else and something_third)',24 ],25)26def test_error(condition):27 code = f"""28 def test_xxx():29 assert {condition}30 """...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Testify automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful