예제 #1
0
def test_multiple_binaries_as_arguments(tempfiles):
    code = textwrap.dedent("""
    from unittest import TestCase
    from tests.support.helpers import requires_salt_modules

    @requires_salt_modules('ps', 'pstree')
    class TestFoo(TestCase):

        def test_one(self):
            assert True
    """)
    expected_code = textwrap.dedent("""
    from unittest import TestCase

    import pytest

    @pytest.mark.requires_salt_modules('ps', 'pstree')
    class TestFoo(TestCase):

        def test_one(self):
            assert True
    """)
    fpath = tempfiles.makepyfile(code, prefix="test_")
    fix_requires_salt_modules_decorator.rewrite(fpath)
    with open(fpath) as rfh:
        new_code = rfh.read()
    assert new_code == expected_code
예제 #2
0
def test_function_level(tempfiles):
    code = textwrap.dedent("""
    from unittest import TestCase
    from tests.support.helpers import requires_salt_modules

    class TestFoo(TestCase):

        @requires_salt_modules('ps')
        def test_one(self):
            assert True
    """)
    expected_code = textwrap.dedent("""
    from unittest import TestCase

    import pytest

    class TestFoo(TestCase):

        @pytest.mark.requires_salt_modules('ps')
        def test_one(self):
            assert True
    """)
    fpath = tempfiles.makepyfile(code, prefix="test_")
    fix_requires_salt_modules_decorator.rewrite(fpath)
    with open(fpath) as rfh:
        new_code = rfh.read()
    assert new_code == expected_code
예제 #3
0
def test_multiple_decorators_same_order(tempfiles):
    code = textwrap.dedent("""
    from unittest import TestCase
    from tests.support.helpers import requires_salt_modules

    @decorator1
    @requires_salt_modules('ps', 'at')
    @pytest.mark.requires_salt_states('blah')
    class Test4(TestCase):

        def test_one(self):
            assert True
    """)
    expected_code = textwrap.dedent("""
    from unittest import TestCase

    import pytest

    @decorator1
    @pytest.mark.requires_salt_modules('ps', 'at')
    @pytest.mark.requires_salt_states('blah')
    class Test4(TestCase):

        def test_one(self):
            assert True
    """)
    fpath = tempfiles.makepyfile(code, prefix="test_")
    fix_requires_salt_modules_decorator.rewrite(fpath)
    with open(fpath) as rfh:
        new_code = rfh.read()
    assert new_code == expected_code
예제 #4
0
def test_pytest_marker_bad_input(tempfiles):
    code = textwrap.dedent("""
    from unittest import TestCase

    import pytest

    class TestFoo(TestCase):

        @pytest.mark.requires_salt_modules(('python2', 'python3'))
        def test_one(self):
            assert True

        @pytest.mark.requires_salt_modules(['python4', 'python5'])
        def test_one(self):
            assert True

        @pytest.mark.requires_salt_modules({'python4', 'python5'})
        def test_one(self):
            assert True
    """)
    expected_code = textwrap.dedent("""
    from unittest import TestCase

    import pytest

    class TestFoo(TestCase):

        @pytest.mark.requires_salt_modules('python2', 'python3')
        def test_one(self):
            assert True

        @pytest.mark.requires_salt_modules('python4', 'python5')
        def test_one(self):
            assert True

        @pytest.mark.requires_salt_modules('python4', 'python5')
        def test_one(self):
            assert True
    """)
    fpath = tempfiles.makepyfile(code, prefix="test_")
    fix_requires_salt_modules_decorator.rewrite(fpath)
    with open(fpath) as rfh:
        new_code = rfh.read()
    assert new_code == expected_code