Пример #1
0
 def test_set_all(self):
     """
     Tests setting the reproducibility setting to ALL
     """
     drop_a = AbstractDROP("a", "a")
     self.assertIsNone(drop_a.merkleroot)
     drop_a.reproducibility_level = ReproducibilityFlags.ALL
     self.assertTrue(isinstance(drop_a.merkleroot, dict))
Пример #2
0
 def test_null_merkleroot(self):
     """
     Sanity check that the default MerkleRoot of an abstract drop is Null
     Consider it a cardinal sin to change this.
     """
     drop_a = AbstractDROP("a", "a")
     self.assertIsNone(drop_a.merkleroot)
Пример #3
0
 def test_recommit(self):
     """
     Should raise an exception preventing a straight-recommit.
     """
     a = AbstractDROP('a', 'a')
     a.reproducibility_level = ReproducibilityFlags.RERUN
     a.setCompleted()
     with self.assertRaises(Exception):
         a.commit()
Пример #4
0
 def test_set_all_set_rerun(self):
     """
     Tests taking a drop that was set to ALL to be set to RERUN and have data structures
     reset correctly.
     """
     drop_a = AbstractDROP("a", "a")
     self.assertIsNone(drop_a.merkleroot)
     drop_a.reproducibility_level = ReproducibilityFlags.ALL
     drop_a.commit()
     self.assertTrue(isinstance(drop_a.merkleroot, dict))
     drop_a.reproducibility_level = ReproducibilityFlags.RERUN
     drop_a.commit()
     self.assertTrue(isinstance(drop_a.merkleroot, str))
Пример #5
0
 def test_drop_get_multiple(self):
     """
     Tests the AbstractDROP multiple fetch routine functions correctly with a single environment
     drop
     """
     env_name = "env_vars"
     env_drop = create_std_env_vars(name=env_name)
     test_drop = AbstractDROP(uid="b", oid="b")
     test_drop.addProducer(env_drop)
     expected_vars = [
         f"${env_name}.uid",
         "/HOME/",
         3,
         False,
         0.5,
         {
             "first": 1,
             "second": "sec"
         },
         [1, 2.0, "3"],
         f"${env_name}.non_var",
     ]
     query_keys = [
         "uid",
         "dir_var",
         "int_var",
         "bool_var",
         "float_var",
         "dict_var",
         "list_var",
         "non_var",
     ]
     query_keys = [f"${env_name}.{x}"
                   for x in query_keys]  # Build queries of the correct form
     # Add some purposefully malformed vars
     extra_keys = ["dir_var", "$non_store.non_var"]
     query_keys.extend(extra_keys)
     expected_vars.extend(extra_keys)
     self.assertEqual(expected_vars,
                      test_drop.get_environment_variables(query_keys))
Пример #6
0
 def test_generate_rerun_data(self):
     """
     Tests that completed Rerun data contains the completed flag.
     """
     drop_a = AbstractDROP("a", "a")
     drop_a.reproducibility_level = ReproducibilityFlags.RERUN
     drop_a.setCompleted()
     self.assertEqual(drop_a.generate_rerun_data(),
                      {"status": DROPStates.COMPLETED})
Пример #7
0
 def test_generate_rerun_data(self):
     """
     Tests that completed Rerun data contains the completed flag.
     """
     a = AbstractDROP('a', 'a')
     a.reproducibility_level = ReproducibilityFlags.RERUN
     a.setCompleted()
     self.assertEqual(a.generate_rerun_data(),
                      {'status': DROPStates.COMPLETED})
Пример #8
0
    def test_commit_on_complete(self):
        """
        Tests that merkle_data is generated upon set_complete status and is correct (NOTHING, RERUN)
        """

        drop_a = AbstractDROP("a", "a")
        drop_b = AbstractDROP("b", "b")
        drop_a.reproducibility_level = ReproducibilityFlags.RERUN
        drop_b.reproducibility_level = ReproducibilityFlags.NOTHING
        self.assertIsNone(drop_a.merkleroot)
        self.assertIsNone(drop_b.merkleroot)

        # Test RERUN
        drop_a.setCompleted()
        test = MerkleTree({"status": DROPStates.COMPLETED}.items(),
                          common_hash)
        # 689fcf0d74c42200bef177db545adc43c135dfb0d7dc85b166db3af1dcded235
        self.assertTrue(test.merkle_root == drop_a.merkleroot)

        # Test NOTHING
        drop_b.setCompleted()
        # None
        self.assertIsNone(drop_b.merkleroot)
        self.assertTrue(drop_b._committed)
Пример #9
0
 def test_drop_get_empty(self):
     """
     Tests the case where the environment drop has no name
     """
     env_name = ""
     env_drop = create_empty_env_vars(name=env_name)
     test_drop = AbstractDROP(uid="c", oid="c")
     test_drop.addProducer(env_drop)
     self.assertEqual("", test_drop.get_environment_variable(""))
     self.assertEqual("$", test_drop.get_environment_variable("$"))
Пример #10
0
 def test_get_dlg_vars(self):
     test_drop = AbstractDROP(
         oid="a",
         uid="a",
         dlg_root="$DLG_ROOT",
         non_dlg_var="$DLG_NONEXISTS",
         non_var=set(),
     )
     test_drop.autofill_environment_variables()
     self.assertEqual(getDlgDir(), test_drop.parameters["dlg_root"])
     self.assertEqual(getDlgDir(),
                      test_drop.get_environment_variable("$DLG_ROOT"))
     self.assertEqual("$DLG_NONEXISTS", test_drop.parameters["non_dlg_var"])
     self.assertEqual("$DLG_NONEXISTS",
                      test_drop.get_environment_variable("$DLG_NONEXISTS"))
Пример #11
0
 def test_autofill_environment_vars(self):
     """
     Tests the autofilling functionality of AbstractDROP
     """
     env_drop = create_std_env_vars(name="env_vars")
     test_drop = AbstractDROP(
         oid="a",
         uid="a",
         dir_var="$env_vars.dir_var",
         int_var="$env_vars.int_var",
         non_var=set(),
     )
     test_drop.addProducer(env_drop)
     test_drop.autofill_environment_variables()
     self.assertEqual("/HOME/", test_drop.parameters["dir_var"])
     self.assertEqual(3, test_drop.parameters["int_var"])
Пример #12
0
    def test_set_reproducibility_level(self):
        """
        Tests functionality for changing a DROP's reproducibility flag
        If already committed. The drop should reset and re-commit all reproducibility data
        If not committed, the change can proceed simply.
        """
        drop_a = AbstractDROP("a", "a")
        drop_b = AbstractDROP("b", "b")
        drop_a.reproducibility_level = ReproducibilityFlags.NOTHING
        drop_b.reproducibility_level = ReproducibilityFlags.NOTHING

        drop_a.setCompleted()
        self.assertIsNone(drop_a.merkleroot)
        drop_a.reproducibility_level = ReproducibilityFlags.RERUN
        drop_a.commit()
        self.assertIsNotNone(drop_a.merkleroot)

        self.assertIsNone(drop_b.merkleroot)
        drop_b.reproducibility_level = ReproducibilityFlags.RERUN
        drop_b.setCompleted()
        self.assertIsNotNone(drop_b.merkleroot)

        with self.assertRaises(TypeError):
            drop_a.reproducibility_level = "REPEAT"
Пример #13
0
    def test_set_reproducibility_level(self):
        """
        Tests functionality for changing a DROP's reproducibility flag
        If already committed. The drop should reset and re-commit all reproducibility data
        If not committed, the change can proceed simply.
        """
        a = AbstractDROP('a', 'a')
        b = AbstractDROP('b', 'b')
        a.reproducibility_level = ReproducibilityFlags.NOTHING
        b.reproducibility_level = ReproducibilityFlags.NOTHING

        a.setCompleted()
        self.assertIsNone(a.merkleroot)
        a.reproducibility_level = ReproducibilityFlags.RERUN
        self.assertIsNotNone(a.merkleroot)

        self.assertIsNone(b.merkleroot)
        b.reproducibility_level = ReproducibilityFlags.RERUN
        b.setCompleted()
        self.assertIsNotNone(b.merkleroot)

        with self.assertRaises(TypeError):
            a.reproducibility_level = 'REPEAT'
Пример #14
0
 def test_drop_get_multiEnv(self):
     """
     Tests the AbstractDROP fetch routine with multiple environment drops
     """
     env1_name = "env_vars"
     env2_name = "more_vars"
     env1_drop = create_std_env_vars(name=env1_name)
     env2_drop = EnvironmentVarDROP(oid="d",
                                    uid="d",
                                    nm=env2_name,
                                    dir_var="/DIFFERENT/",
                                    int_var=4)
     test_drop = AbstractDROP(uid="c", oid="c")
     test_drop.addProducer(env1_drop)
     test_drop.addProducer(env2_drop)
     self.assertEqual(
         "/HOME/",
         test_drop.get_environment_variable(f"${env1_name}.dir_var"))
     self.assertEqual(
         "/DIFFERENT/",
         test_drop.get_environment_variable(f"${env2_name}.dir_var"))
     self.assertEqual(
         3, test_drop.get_environment_variable(f"${env1_name}.int_var"))
     self.assertEqual(
         4, test_drop.get_environment_variable(f"${env2_name}.int_var"))
     self.assertEqual(
         f"{env1_name}.int_var",
         test_drop.get_environment_variable(f"{env1_name}.int_var"),
     )
     self.assertEqual(f".int_var",
                      test_drop.get_environment_variable(f".int_var"))
     self.assertEqual(
         f"$third_env.int_var",
         test_drop.get_environment_variable(f"$third_env.int_var"),
     )
     self.assertEqual(
         [
             "/HOME/", "/DIFFERENT/", 3, 4, f"${env1_name}.non_var",
             "$fake.var"
         ],
         test_drop.get_environment_variables([
             f"${env1_name}.dir_var",
             f"${env2_name}.dir_var",
             f"${env1_name}.int_var",
             f"${env2_name}.int_var",
             f"${env1_name}.non_var",
             "$fake.var",
         ]),
     )
Пример #15
0
 def test_drop_get_single(self):
     """
     Tests the AbstractDROP fetch routine functions correctly with a single environment drop
     """
     env_drop = create_std_env_vars()
     test_drop = AbstractDROP(uid="b", oid="b")
     test_drop.addProducer(env_drop)
     self.assertEqual(
         "/HOME/", test_drop.get_environment_variable("$env_vars.dir_var"))
     self.assertEqual(
         3, test_drop.get_environment_variable("$env_vars.int_var"))
     self.assertEqual(
         False, test_drop.get_environment_variable("$env_vars.bool_var"))
     self.assertEqual(
         0.5, test_drop.get_environment_variable("$env_vars.float_var"))
     self.assertEqual(
         {
             "first": 1,
             "second": "sec"
         },
         test_drop.get_environment_variable("$env_vars.dict_var"),
     )
     self.assertEqual(
         [1, 2.0, "3"],
         test_drop.get_environment_variable("$env_vars.list_var"))
     self.assertEqual(
         "$env_vars.non_var",
         test_drop.get_environment_variable("$env_vars.non_var"))
     self.assertEqual("$env_vars.uid",
                      test_drop.get_environment_variable("$env_vars.uid"))