Example #1
0
 def test_init_dict(self):
     d = {"foo": 23, "test case": "bar"}
     pl = InputList(d)
     self.assertEqual(tuple(pl.items()), tuple(d.items()),
                      "source dict items not preserved")
     with self.assertRaises(ValueError,
                            msg="no ValueError on invalid initializer"):
         pl = InputList({2: 0, 1: 1})
Example #2
0
 def test_init_tuple(self):
     t = (1, 2, 3, 4)
     pl = InputList(t)
     self.assertEqual(len(pl), len(t),
                      "not the same length as source tuple")
     self.assertEqual(tuple(pl.values()), t,
                      "conversion to tuple not the same as source tuple")
Example #3
0
 def test_set_append(self):
     pl = InputList()
     # should not raise and exception
     pl[0] = 1
     pl[1] = 2
     self.assertEqual(pl[0], 1, "append via index broken on empty list")
     self.assertEqual(pl[1], 2, "append via index broken on non-empty list")
Example #4
0
 def __init__(self, project, job_name):
     super(ScriptJob, self).__init__(project, job_name)
     self.__version__ = "0.1"
     self.__hdf_version__ = "0.2.0"
     self.__name__ = "Script"
     self._script_path = None
     self.input = InputList(table_name="custom_dict")
Example #5
0
 def test_to_hdf_group(self):
     self.pl.to_hdf(hdf=self.hdf, group_name="test_group")
     self.assertEqual(self.hdf["test_group/NAME"], "InputList")
     self.assertEqual(self.hdf["test_group/TYPE"],
                      "<class 'pyiron_base.generic.inputlist.InputList'>")
     self.assertEqual(self.hdf["test_group/OBJECT"], "InputList")
     l = InputList(self.hdf["test_group/data"])
     self.assertEqual(self.pl, l)
Example #6
0
    def test_to_hdf(self):
        self.pl.to_hdf(hdf=self.hdf)
        self.assertEqual(self.hdf["input/NAME"], "InputList")
        self.assertEqual(self.hdf["input/OBJECT"], "InputList")
        self.assertEqual(self.hdf["input/TYPE"],
                         "<class 'pyiron_base.generic.inputlist.InputList'>")
        l = InputList(self.hdf["input/data"])
        self.assertEqual(self.pl, l)

        pl = InputList(self.pl)
        pl.to_hdf(hdf=self.hdf)
        self.assertEqual(self.hdf["NAME"], "InputList")
        self.assertEqual(self.hdf["OBJECT"], "InputList")
        self.assertEqual(self.hdf["TYPE"],
                         "<class 'pyiron_base.generic.inputlist.InputList'>")
        l = InputList(self.hdf["data"])
        self.assertEqual(pl, l)
Example #7
0
    def setUpClass(cls):
        cls.pl = InputList([{
            "foo": "bar"
        }, 2, 42, {
            "next": [0, {
                "depth": 23
            }]
        }],
                           table_name="input")
        cls.pl["tail"] = InputList([2, 4, 8])

        file_location = os.path.dirname(os.path.abspath(__file__))
        pr = Project(file_location)
        cls.file_name = os.path.join(file_location, "input.h5")
        cls.hdf = ProjectHDFio(project=pr,
                               file_name=cls.file_name,
                               h5_path="/test",
                               mode="a")
Example #8
0
 def test_get_nested(self):
     n = [{"foo": "bar"}, 2, 42, {"next": [0, {"depth": 23}]}]
     pl = InputList(n)
     self.assertEqual(type(pl[0]), InputList,
                      "nested dict not converted to InputList")
     self.assertEqual(type(pl["3/next"]), InputList,
                      "nested list not converted to InputList")
     self.assertEqual(type(pl["0/foo"]), str,
                      "nested str converted to InputList")
Example #9
0
 def test_mark(self):
     pl = InputList([1, 2, 3])
     pl.mark(1, "foo")
     self.assertEqual(pl[1], pl.foo,
                      "marked element does not refer to correct element")
     pl.mark(2, "foo")
     self.assertEqual(pl[2], pl.foo, "marking with existing key broken")
     with self.assertRaises(IndexError,
                            msg="no IndexError on invalid index"):
         pl.mark(10, "foo")
Example #10
0
    def test_from_hdf_readonly(self):
        self.pl.to_hdf(hdf=self.hdf, group_name="read_only_from")
        pl = InputList()
        pl.from_hdf(self.hdf, group_name="read_only_from")
        self.assertEqual(pl.read_only, self.hdf["read_only_from/read_only"],
                         "read-only parameter not correctly read from HDF")

        self.hdf["read_only_from/read_only"] = True
        pl.from_hdf(self.hdf, group_name="read_only_from")
        self.assertEqual(pl.read_only, self.hdf["read_only_from/read_only"],
                         "read-only parameter not correctly read from HDF")
Example #11
0
 def test_insert(self):
     pl = InputList([1, 2, 3])
     pl.insert(1, 42, key="foo")
     self.assertTrue(pl[0] == 1 and pl[1] == 42 and pl[2] == 2,
                     "insert does not properly set value")
     pl.insert(1, 24, key="bar")
     self.assertTrue(pl[0] == 1 and pl.bar == 24 and pl.foo == 42,
                     "insert does not properly update keys")
     pl.insert(10, 4)
     self.assertEqual(pl[-1], 4,
                      "insert does not handle out of bounds gracefully")
Example #12
0
    def test_del_item(self):
        pl = InputList({0: 1, "a": 2, "foo": 3})

        with self.assertRaises(ValueError,
                               msg="no ValueError on invalid index type"):
            del pl[{}]

        del pl["a"]
        self.assertTrue("a" not in pl, "delitem does not delete with str key")
        del pl[0]
        self.assertTrue(pl[0] != 1, "delitem does not delete with index")
Example #13
0
    def test_update(self):
        pl = InputList()
        d = self.pl.to_builtin()
        pl.update(d, wrap=True)
        self.assertEqual(pl, self.pl,
                         "update from to_builtin does not restore list")
        with self.assertRaises(ValueError,
                               msg="no ValueError on invalid initializer"):
            pl.update("asdf")

        pl = self.pl.copy()
        pl.update({}, pyiron="yes", test="case")
        self.assertEqual((pl.pyiron, pl.test), ("yes", "case"),
                         "update via kwargs does not set values")
        pl.clear()
        d = {"a": 0, "b": 1, "c": 2}
        pl.update(d)
        self.assertEqual(
            dict(pl), d, "update without options does not call generic method")
Example #14
0
 def test_init_set(self):
     s = {1, 2, 3, 4}
     pl = InputList(s)
     self.assertEqual(len(pl), len(s), "not the same length as source set")
     self.assertEqual(set(pl.values()), s,
                      "conversion to set not the same as source set")
Example #15
0
 def test_init_list(self):
     l = [1, 2, 3, 4]
     pl = InputList(l)
     self.assertEqual(len(pl), len(l), "not the same length as source list")
     self.assertEqual(list(pl.values()), l,
                      "conversion to list not the same as source list")
Example #16
0
 def test_init_none(self):
     pl = InputList()
     self.assertEqual(len(pl), 0, "not empty after initialized with None")
Example #17
0
 def test_set_some_keys(self):
     pl = InputList([1, 2])
     pl["end"] = 3
     self.assertEqual(pl, InputList({0: 1, 1: 2, "end": 3}))
Example #18
0
 def __init__(self, project, job_name):
     super(ImageJob, self).__init__(project, job_name)
     self.__name__ = "ImageJob"
     self._images = DistributingList()
     self.input = InputList(table_name="input")
     self.output = InputList(table_name="output")
Example #19
0
 def test_numpy_array(self):
     pl = InputList([1, 2, 3])
     self.assertTrue((np.array(pl) == np.array([1, 2, 3])).all(),
                     "conversion to numpy array broken")
Example #20
0
 def test_from_hdf_group(self):
     self.pl.to_hdf(hdf=self.hdf, group_name="test_group")
     l = InputList(table_name="input")
     l.from_hdf(hdf=self.hdf, group_name="test_group")
     self.assertEqual(self.pl, l)
Example #21
0
 def test_get_attr(self):
     self.assertEqual(self.pl.tail, InputList([2, 4, 8]),
                      "attribute access does not give correct element")
     self.assertEqual(
         self.pl[3].next, InputList([0, InputList({"depth": 23})]),
         "nested attribute access does not give correct element")
Example #22
0
 def test_extend(self):
     pl = InputList()
     pl.extend([1, 2, 3])
     self.assertEqual(list(pl.values()), [1, 2, 3],
                      "extend from list does not set values")
Example #23
0
 def test_deprecation_warning(self):
     """Instantiating an InputList should raise a warning."""
     with self.assertWarns(DeprecationWarning,
                           msg="InputList raises no DeprecationWarning!"):
         InputList([1, 2, 3])
Example #24
0
 def test_from_hdf(self):
     self.pl.to_hdf(hdf=self.hdf)
     l = InputList(table_name="input")
     l.from_hdf(hdf=self.hdf)
     self.assertEqual(self.pl, l)