def test_barebone(): hook = auto_self.add_hook() result = auto_self.automatic_self(cls_source) assert result == cls_expected, "auto_self test" remove_hook(hook)
def test_import_with_hook(): hook = decimal_math.add_hook() try: from . import use_hook # for testing as part of a suite with pytest except ImportError: import use_hook # for testing only this file remove_hook(hook)
def test_uppercase(): hook = constants.add_hook() # The following module contains assertions confirming that it # is processed correctly when it is created. print("Importing uppercase.py") try: import uppercase except ImportError: from . import uppercase print("\nAttempting to change values of uppercase attributes.") # The following confirm that attempts to modify it indirectly will fail assert uppercase.XX == 36, "Cannot change value of uppercase constant" del uppercase.XX uppercase.XX = "something else" assert uppercase.XX == 36, "Cannot change uppercase constant" # The following should not raise any error uppercase.new = 1 uppercase.new = 3 assert uppercase.new == 3, "Non constant values can be changed" del uppercase.new remove_hook(hook)
def test_final(on_prevent_change=None): hook = constants.add_hook(on_prevent_change=on_prevent_change) # The following module contains assertions confirming that it # is processed correctly when it is created. if on_prevent_change is None: print("Importing final.py") try: import final except ImportError: from . import final if on_prevent_change is None: print("\nAttempting to change values of final attributes.") # The following confirm that attempts to modify constants indirectly will fail assert final.const == 1, "In test: confirm initial value of final constant" final.const = 2 final.const += 36 assert final.const == 1, "In test: confirm value of final constant did not change" # The following should not raise any error final.new = 1 final.new = 3 assert final.new == 3, "Non constant values can be changed" del final.new remove_hook(hook)
def test_repeat_error(): hook = repeat.add_hook() with pytest.raises(repeat.RepeatSyntaxError): from . import program_with_error remove_hook(hook)
def test_simple_case(): hook = confused_math_bc.add_hook() try: import confused_math # for testing only this file except ImportError: from . import confused_math # for testing as part of a suite with pytest remove_hook(hook)
def test_simple_addition(): hook = fractions_ast.add_hook() try: import addition # for testing only this file except ImportError: from . import addition # for testing as part of a suite with pytest remove_hook(hook)
def test_predictable2(): hook = repeat.add_hook(predictable_names=True) try: import my_program # for testing only this file except ImportError: from . import my_program # for testing as part of a suite with pytest assert my_program.one_loop == 4, "one_loop should equal 4" assert my_program.two_loops == 16, "two_loops should equal 16" remove_hook(hook)
def test_french(): hook = french.add_hook() try: import mon_programme # for testing only this file except ImportError: from . import mon_programme # for testing as part of a suite with pytest assert mon_programme.carré(4) == 16, "The square of 4 is 16" remove_hook(hook)
def test_function(): hook = function_keyword.add_hook() try: import my_program # for testing only this file except ImportError: from . import my_program # for testing as part of a suite with pytest assert my_program.square(4) == 16, "The square of 4 is 16" remove_hook(hook) print("test_function() ran successfully.")
def test_function_simplest(): hook = function_simplest.add_hook() try: import my_program except ImportError: from . import my_program assert my_program.square(-3) == 9, "The square of -3 is 9" remove_hook(hook) print("test_function_simplest() ran successfully.")
def no_pytest_repeat_error(): hook = repeat.add_hook() error_found = False try: import program_with_error except repeat.RepeatSyntaxError: error_found = True assert error_found, "RepeatSyntaxError was caught properly" remove_hook(hook)
def test_pep_557(): hook = auto_self.add_hook() result = auto_self.automatic_self(pep_557_source) assert result == pep_557_expected, "PEP 557 auto_self test" result_other = auto_self.automatic_self(pep_557_source_other) result_other = result_other.replace("cls", "self") assert result_other == pep_557_expected, "PEP 557 auto_self test other" remove_hook(hook)