def test_persist(self): try: Registry.set(1, 2, 3, 4) tmp = tempfile.mkdtemp() file_path = os.path.join(tmp, "foo.json") Registry.persist(file_path) Registry.set(1, 2, 3, 5) Registry._obj = {} Registry.from_file(file_path) self.assertEqual({"1": {"2": {"3": 4}}}, Registry()) finally: shutil.rmtree(tmp)
def test_from_file(self): try: tmp = tempfile.mkdtemp() file_path = os.path.join(tmp, "foo.json") with open(file_path, "w") as fp: json.dump(dict(a=True), fp) Registry.from_file(file_path) self.assertEqual(dict(a=True), Registry()) Registry.set("a", False) self.assertFalse(Registry.get("a")) Registry.from_file(file_path) self.assertFalse(Registry.get("a")) finally: shutil.rmtree(tmp)
def init_registry(self): cfg = os.path.join(click.get_app_dir("pytuber", False), "storage.db") Registry.from_file(cfg)