Esempio n. 1
0
 def test_allow_setting_keys_and_attributes(self):
     d = EasyDict({"a": 2, "b": 3})
     d["a"] = 4
     self.assertEqual(d["a"], 4)
     self.assertEqual(d.a, 4)
     d.c = 9
     self.assertEqual(d["c"], 9)
     self.assertEqual(d.c, 9)
     self.assertEqual(d["b"], 3)
     x = EasyDict()
     y = EasyDict()
     x.a = 4
     y.a = 5
     self.assertEqual(x.a, 4)
Esempio n. 2
0
 def test_normalize_arg(self):
     d = EasyDict({"greeting 1": "hi"}, normalize=True)
     self.assertEqual(d["greeting 1"], "hi")
     self.assertEqual(d.greeting_1, "hi")
     d.greeting_2 = "hello"
     self.assertEqual(d["greeting 2"], "hello")
     self.assertEqual(d.greeting_2, "hello")
     d["greeting 2"] = "hey"
     self.assertEqual(d["greeting 2"], "hey")
     self.assertEqual(d.get("greeting 2"), "hey")
     self.assertEqual(d.greeting_2, "hey")
     with self.assertRaises(AttributeError):
         d.greeting2
     d = EasyDict({"greeting 1": "hi"})
     self.assertEqual(d["greeting 1"], "hi")
     with self.assertRaises(AttributeError):
         d.greeting_1
Esempio n. 3
0
 def test_keyword_arguments_equality_and_get_method(self):
     d = EasyDict(a=2, b=3, c=4, d=5)
     self.assertEqual(d.a, 2)
     self.assertEqual(d.b, 3)
     self.assertEqual(d["c"], 4)
     self.assertEqual(d["d"], 5)
     x = EasyDict({"a": 2, "b": 3})
     y = EasyDict({"a": 2, "b": 4})
     self.assertNotEqual(x, y)
     y.b = 3
     self.assertEqual(x, y)
     x.c = 5
     self.assertNotEqual(x, y)
     y.c = 5
     self.assertEqual(x, y)
     self.assertIsNone(y.get("d"))
     self.assertEqual(y.get("c"), 5)
     self.assertEqual(y.get("d", 5), 5)
Esempio n. 4
0
    def __init__(self, opts: DriverOptions, models,
                 train_datasets,
                 val_datasets,
                 test_datasets=None,
                 train_transform=None,
                 val_transform=None,
                 test_transform=None) -> None:
        self.opts = EasyDict(opts)
        self.train_transform = train_transform
        self.val_transform = val_transform
        self.models = models.to(self.opts.device)
        self.val_interval = 1000

        self.train_loader = self._prepare_data_loader(
            train_datasets, train_transform)
        self.val_loader = self._prepare_data_loader(
            val_datasets, train_transform)
        self.test_loader = self._prepare_data_loader(
            test_datasets, test_transform)
        self.optimizers = self.configure_optimizers(self.models)
Esempio n. 5
0
 def test_original_dictionary_unchanged(self):
     mapping = {"a": 2, "b": 3}
     d = EasyDict(mapping)
     d.c = 4
     self.assertEqual(mapping, {"a": 2, "b": 3})
Esempio n. 6
0
 def test_attribute_access(self):
     d = EasyDict({"a": 2, "b": 3})
     self.assertEqual(d.a, 2)
     self.assertEqual(d.b, 3)
Esempio n. 7
0
 def test_key_access(self):
     d = EasyDict({"a": 2, "b": 3})
     self.assertEqual(d["a"], 2)
     self.assertEqual(d["b"], 3)
Esempio n. 8
0
 def test_constructor(self):
     EasyDict()
     EasyDict({"a": 2, "b": 3})