Exemplo n.º 1
0
class TestSavingFixesSUT(SavingFixesSUT):
    tests = [
        # call missing function with literal argument
        standard_test_spec(
            """
            arg = 1
            bla = blubb.some_function(arg, 42)
            """),
        # call missing function with two literal arguments
        standard_test_spec(
            """
            bla = blubb.some_function(41, 42)
            """),
        # missing function with default argument
        standard_test_spec(
            """
            arg = 1
            bla = blubb.some_function(a=42)
            bla = blubb.some_function(arg)
            """),
        # missing function with normal and default argument
        standard_test_spec(
            """
            arg = 1
            bla = blubb.some_function(arg, a=42)
            bla = blubb.some_function(arg)
            """),
        # argument names might clash with generated names
        standard_test_spec(
            """
            arg0 = 1
            arg1 = 1
            arg4 = 1
            bla = blubb.some_function(arg4, arg0, 42, arg1)
            """),
        # create object of missing class with unary constructor
        standard_test_spec(
            """
            a = blubb.Something(17)
            """),
        # create object of missing class with attribute
        standard_test_spec(
            """
            a = blubb.Something()
            b = a.attribute
            """),
        # create object of missing class with nullary method
        standard_test_spec(
            """
            a = blubb.Something()
            b = a.fun()
            """),
        # create object of missing class with unary method
        standard_test_spec(
            """
            a = blubb.Something(42)
            """),
        ]\
        + [missing_function_in_source(args) for args in various_argument_lists]
Exemplo n.º 2
0
class TestSavingFixesMissingVariables(SavingFixesSUT):
    tests = [
        standard_test_spec(  # add several variables to SUT
            """
            bla = blubb.x
            bla = blubb.y
            bla = blubb.z""")
    ] + [missing_variable_in_source(name) for name in variable_names]
class TestSavingFixesMissingArguments(SavingFixesSUT):
    tests = [
        standard_test_spec(  # add new argument before default argument
            """
            bla = blubb.some_function(1, a=42)
            """, """
            def some_function(a=42):
                pass
            """),
        standard_test_spec(  # fix missing self
            """
            a = blubb.Blubb()
            b = a.some_method(x = 3)
            """, """
            class Blubb:
                def __init__(self):
                    pass
                def some_method(x = 13):
                    pass
            """)
    ]
Exemplo n.º 4
0
class TestSavingDoesNotTouchBrokenStuff(SavingDoesNotTouchBrokenStuff):
    tests = [
        standard_test_spec(  # different number of function arguments
            """
            bla = blubb.random_function(42)
            aaa = blubb.random_function(42, 37)
            """, """
            def random_function():
                pass
            """),
        standard_test_spec(  # using non-existent lib
            'bla = lalelu.x'),
        # using nonexistent lib variable
        AbstractFilePair(
            'blubb', 'import collections\n' +
            in_test_function('Point = collections.random_typo')),
        # using lib variable as function
        AbstractFilePair(
            'blubb', 'import math\n' + in_test_function('Point = math.pi()')),
        # using lib variable as function
        # SUT having same variable name makes the problem harder
        AbstractFilePair(
            'blubb', 'import math\n' + in_test_function('Point = math.pi()'),
            'pi = None\n'),
        # cryptic and broken import
        # (doesn't yet deal with wildcards)
        AbstractFilePair(
            'blubb', 'from lalelu import *\n' +
            in_test_function('self.assertTrue(True)')),
        # adding strings and numbers is broken beyond repair
        # this should test return code JUST_BROKEN
        standard_test_spec('a = 3 + "lol"'),
        standard_test_spec(  # broken function definition (missing colon)
            'bla = blubb.random_function(42)', """
            def random_function()
                pass
            """)
    ]
Exemplo n.º 5
0
class TestSavingFixesMissingFunction(SavingFixesSUT):
    tests = [
        # create object of missing class with nullary constructor
        standard_test_spec("a = blubb.Something()"),
        standard_test_spec("a = blubb.fun()")]
Exemplo n.º 6
0
class TestSavingFixesMissingImport(FailingTestGetsFixed):
    tests = [
        standard_test_spec(  # missing import of lib
            "Point = collections.namedtuple('Point', ['x', 'y'])")
    ] + [missing_import_of_SUT(name) for name in filenames]