Ejemplo n.º 1
0
 def test_disabled_routine_is_not_written_to_script(self):
     # Make experiment and two test routines
     exp = Experiment()
     rt1 = UnknownRoutine(exp, name="testRoutine1")
     rt2 = UnknownRoutine(exp, name="testRoutine2")
     # Disable one routine
     rt1.params['disabled'].val = True
     rt2.params['disabled'].val = False
     # Add routines to expriment
     exp.addStandaloneRoutine("testRoutine1", rt1)
     exp.flow.addRoutine(rt1, 0)
     exp.addStandaloneRoutine("testRoutine2", rt2)
     exp.flow.addRoutine(rt2, 0)
     # Write python script
     pyScript = exp.writeScript(target="PsychoPy")
     # Check that one routine is present and the other is not
     assert "testRoutine1" not in pyScript and "testRoutine2" in pyScript
Ejemplo n.º 2
0
    def test_muting(self):
        """
        Test that component and standalone routines are muted under the correct conditions (i.e. if target is unimplemented or if disabled)
        """
        # Make experiment to hold everything
        exp = Experiment()
        comp_rt = Routine("comp_rt", exp)
        comp_rt = exp.addRoutine("comp_rt", comp_rt)
        exp.flow.append(comp_rt)

        # Define some routines/components which should or should not compile
        exemplars = []

        # standalone routine + disabled + no target
        obj = UnknownRoutine(exp, name="test_rt_disabled_notarget")
        obj.disabled = True
        obj.targets = []
        exp.addStandaloneRoutine(obj.name, obj)
        exp.flow.append(obj)
        exemplars.append({"obj": obj, "ans": []})
        # standalone routine + disabled + py target
        obj = UnknownRoutine(exp, name="test_rt_disabled_pytarget")
        obj.disabled = True
        obj.targets = ['PsychoPy']
        exp.addStandaloneRoutine(obj.name, obj)
        exp.flow.append(obj)
        exemplars.append({"obj": obj, "ans": []})
        # standalone routine + disabled + js target
        obj = UnknownRoutine(exp, name="test_rt_disabled_jstarget")
        obj.disabled = True
        obj.targets = ['PsychoJS']
        exp.addStandaloneRoutine(obj.name, obj)
        exp.flow.append(obj)
        exemplars.append({"obj": obj, "ans": []})
        # standalone routine + disabled + both targets
        obj = UnknownRoutine(exp, name="test_rt_disabled_bothtarget")
        obj.disabled = True
        obj.targets = ['PsychoPy', 'PsychoJS']
        exp.addStandaloneRoutine(obj.name, obj)
        exp.flow.append(obj)
        exemplars.append({"obj": obj, "ans": []})
        # standalone routine + enabled + no target
        obj = UnknownRoutine(exp, name="test_rt_enabled_notarget")
        obj.disabled = False
        obj.targets = []
        exp.addStandaloneRoutine(obj.name, obj)
        exp.flow.append(obj)
        exemplars.append({"obj": obj, "ans": obj.targets})
        # standalone routine + enabled + py target
        obj = UnknownRoutine(exp, name="test_rt_enabled_pytarget")
        obj.disabled = False
        obj.targets = ['PsychoPy']
        exp.addStandaloneRoutine(obj.name, obj)
        exp.flow.append(obj)
        exemplars.append({"obj": obj, "ans": obj.targets})
        # standalone routine + enabled + js target
        obj = UnknownRoutine(exp, name="test_rt_enabled_jstarget")
        obj.disabled = False
        obj.targets = ['PsychoJS']
        exp.addStandaloneRoutine(obj.name, obj)
        exp.flow.append(obj)
        exemplars.append({"obj": obj, "ans": obj.targets})
        # standalone routine + enabled + both target
        obj = UnknownRoutine(exp, name="test_rt_enabled_bothtarget")
        obj.disabled = False
        obj.targets = ['PsychoPy', 'PsychoJS']
        exp.addStandaloneRoutine(obj.name, obj)
        exp.flow.append(obj)
        exemplars.append({"obj": obj, "ans": obj.targets})

        # component + disabled + no target
        obj = UnknownComponent(exp, parentName="comp_rt", name="test_cmp_disabled_notarget")
        obj.disabled = True
        obj.targets = []
        comp_rt.addComponent(obj)
        exemplars.append({"obj": obj, "ans": []})
        # component + disabled + py target
        obj = UnknownComponent(exp, parentName="comp_rt", name="test_cmp_disabled_pytarget")
        obj.disabled = True
        obj.targets = ['PsychoPy']
        comp_rt.addComponent(obj)
        exemplars.append({"obj": obj, "ans": []})
        # component + disabled + js target
        obj = UnknownComponent(exp, parentName="comp_rt", name="test_cmp_disabled_jstarget")
        obj.disabled = True
        obj.targets = ['PsychoJS']
        comp_rt.addComponent(obj)
        exemplars.append({"obj": obj, "ans": []})
        # component + disabled + both target
        obj = UnknownComponent(exp, parentName="comp_rt", name="test_cmp_disabled_bothtarget")
        obj.disabled = True
        obj.targets = ['PsychoPy', 'PsychoJS']
        comp_rt.addComponent(obj)
        exemplars.append({"obj": obj, "ans": []})
        # component + enabled + no target
        obj = UnknownComponent(exp, parentName="comp_rt", name="test_cmp_enabled_notarget")
        obj.disabled = False
        obj.targets = []
        comp_rt.addComponent(obj)
        exemplars.append({"obj": obj, "ans": obj.targets})
        # component + enabled + py target
        obj = UnknownComponent(exp, parentName="comp_rt", name="test_cmp_enabled_pytarget")
        obj.disabled = False
        obj.targets = ['PsychoPy']
        comp_rt.addComponent(obj)
        exemplars.append({"obj": obj, "ans": obj.targets})
        # component + enabled + js target
        obj = UnknownComponent(exp, parentName="comp_rt", name="test_cmp_enabled_jstarget")
        obj.disabled = False
        obj.targets = ['PsychoJS']
        comp_rt.addComponent(obj)
        exemplars.append({"obj": obj, "ans": obj.targets})
        # component + enabled + both target
        obj = UnknownComponent(exp, parentName="comp_rt", name="test_cmp_enabled_bothtarget")
        obj.disabled = False
        obj.targets = ['PsychoPy', 'PsychoJS']
        comp_rt.addComponent(obj)
        exemplars.append({"obj": obj, "ans": obj.targets})

        tykes = []

        # Compile experiment
        pyScript = exp.writeScript(target="PsychoPy")
        # jsScript = exp.writeScript(target="PsychoJS")  ## disabled until js can compile without saving

        # Test all cases
        for case in exemplars + tykes:
            # Check Python script
            if "PsychoPy" in case['ans']:
                assert case['obj'].name in pyScript, (
                    f"{case['obj']} not found in Python script when it should be."
                )
            else:
                assert case['obj'].name not in pyScript, (
                    f"{case['obj']} found in Python script when it should not be."
                )