示例#1
0
    def test_creates_setup_and_teardown_for_two_different_global_read_side_effects(
            self):
        call = create(FunctionCall, args={})
        old_value = ImmutableObject('old_value')
        se = GlobalRead('mod', 'var', old_value)
        se2 = GlobalRead('mod', 'other_var', old_value)
        call.add_side_effect(se)
        call.add_side_effect(se2)
        put_on_timeline(se, se2, call, call.output)

        timeline = assertions_for_interaction(call)
        varSetup1, varSetup2, varTeardown = assert_timeline_length_and_return_elements(
            filter_out_objects(timeline), 7, [2, 3, 5])
        assert_assignment_with_module_variable_reference(
            varSetup1, 'old_mod_var', 'mod', 'var')
        assert_assignment(varSetup2, 'mod.var', old_value)
        assert_assignment(varTeardown, 'mod.var', 'old_mod_var')

        otherVarSetup1, otherVarSetup2, otherVarTeardown = assert_timeline_length_and_return_elements(
            filter_out_objects(timeline), 7, [0, 1, 6])
        assert_assignment_with_module_variable_reference(
            otherVarSetup1, 'old_mod_other_var', 'mod', 'other_var')
        assert_assignment(otherVarSetup2, 'mod.other_var', old_value)
        assert_assignment(otherVarTeardown, 'mod.other_var',
                          'old_mod_other_var')
示例#2
0
 def global_read(self, module_name, name, value):
     try:
         if has_defined_name(self.execution.project[module_name], name):
             return
     except:
         pass
     se = GlobalRead(module_name, name, self.execution.serialize(value))
     self.call_stack.side_effect(se)
示例#3
0
    def test_creates_only_one_setup_and_teardown_for_multiple_global_read_side_effects_of_the_same_variable(
            self):
        call = create(FunctionCall, args={})
        old_value = ImmutableObject('old_value')
        se = GlobalRead('mod', 'var', old_value)
        se2 = GlobalRead('mod', 'var', old_value)
        call.add_side_effect(se)
        call.add_side_effect(se2)
        put_on_timeline(se, se2, call, call.output)

        timeline = assertions_for_interaction(call)
        setup_1, setup_2, teardown = assert_timeline_length_and_return_elements(
            filter_out_objects(timeline), 4, [0, 1, 3])
        assert_assignment_with_module_variable_reference(
            setup_1, 'old_mod_var', 'mod', 'var')
        assert_assignment(setup_2, 'mod.var', old_value)
        assert_assignment(teardown, 'mod.var', 'old_mod_var')
示例#4
0
    def test_names_globals_from_submodules_properly(self):
        call = create(FunctionCall, args={})
        old_value = ImmutableObject('old_value')
        se = GlobalRead('mod.submod', 'var', old_value)
        call.add_side_effect(se)
        put_on_timeline(se, call, call.output)

        timeline = assertions_for_interaction(call)
        setup_1, setup_2, teardown = assert_timeline_length_and_return_elements(
            filter_out_objects(timeline), 4, [0, 1, 3])
        assert_assignment_with_module_variable_reference(
            setup_1, 'old_mod_submod_var', 'mod.submod', 'var')
        assert_assignment(setup_2, 'mod.submod.var', old_value)
        assert_assignment(teardown, 'mod.submod.var', 'old_mod_submod_var')