def test_boolean(self): data = ( "a : True;" \ "b : False" ) valid = { "a" : True, "b" : False } self.assertEqual(ucl.load(data), valid)
def hbds_release_branch(self) -> str: """Translate the release into a HardenedBSD release git branch name.""" if self._hbsd_release_branch is not None: return self._hbsd_release_branch if self.fetched is False: raise libioc.errors.ReleaseNotFetched( name=self.name, logger=self.logger ) root_dataset_mountpoint = self.root_dataset.mountpoint source_file = f"{root_dataset_mountpoint}/etc/hbsd-update.conf" if not os.path.isfile(source_file): raise libioc.errors.ReleaseUpdateBranchLookup( release_name=self.name, reason=f"{source_file} not found", logger=self.logger ) libioc.helpers.require_no_symlink(source_file, logger=self.logger) with open(source_file, "r", encoding="utf-8") as f: import ucl hbsd_update_conf = ucl.load(f.read()) self._hbsd_release_branch = hbsd_update_conf["branch"] return str(self._hbsd_release_branch)
def test_boolean(self): totest = ( "a : True;" \ "b : False" ) correct = {"a": True, "b": False} self.assertEqual(ucl.load(totest), correct)
def test_every_type(self): totest="""{ "key1": value; "key2": value2; "key3": "value;" "key4": 1.0, "key5": -0xdeadbeef "key6": 0xdeadbeef.1 "key7": 0xreadbeef "key8": -1e-10, "key9": 1 "key10": true "key11": no "key12": yes }""" correct = { 'key1': 'value', 'key2': 'value2', 'key3': 'value;', 'key4': 1.0, 'key5': -3735928559, 'key6': '0xdeadbeef.1', 'key7': '0xreadbeef', 'key8': -1e-10, 'key9': 1, 'key10': 'true', 'key11': 'false', 'key12': 'true', } self.assertEqual(ucl.load(totest), correct)
def test_boolean(self): totest = ( "a : True;" \ "b : False" ) correct = {"a" : True, "b" : False} self.assertEqual(ucl.load(totest), correct)
def hbds_release_branch(self) -> str: """Translate the release into a HardenedBSD release git branch name.""" if self._hbsd_release_branch is not None: return self._hbsd_release_branch if self.fetched is False: raise iocage.errors.ReleaseNotFetched( name=self.name, logger=self.logger ) root_dataset_mountpoint = self.root_dataset.mountpoint source_file = f"{root_dataset_mountpoint}/etc/hbsd-update.conf" if not os.path.isfile(source_file): raise iocage.errors.ReleaseUpdateBranchLookup( release_name=self.name, reason=f"{source_file} not found", logger=self.logger ) with open(source_file, "r") as f: import ucl hbsd_update_conf = ucl.load(f.read()) self._hbsd_release_branch = hbsd_update_conf["branch"] return str(self._hbsd_release_branch)
def test_every_type(self): data = ("""{ "key1": value; "key2": value2; "key3": "value;" "key4": 1.0, "key5": -0xdeadbeef "key6": 0xdeadbeef.1 "key7": 0xreadbeef "key8": -1e-10, "key9": 1 "key10": true "key11": no "key12": yes }""") valid = { 'key1': 'value', 'key2': 'value2', 'key3': 'value;', 'key4': 1.0, 'key5': -3735928559, 'key6': '0xdeadbeef.1', 'key7': '0xreadbeef', 'key8': -1e-10, 'key9': 1, 'key10': True, 'key11': False, 'key12': True, } self.assertEqual(ucl.load(data), valid)
def test_example(self): # load in sample UCL u = ucl.load(_ucl_inp) # Output and read back the JSON uj = json.loads(json.dumps(u)) self.assertEqual(uj, _json_res)
def read_data(self): with open(JailConfigLegacy.__get_config_path(self), "r") as conf: data = ucl.load(conf.read()) try: if data["type"] == "basejail": data["basejail"] = "on" data["clonejail"] = "off" data["basejail_type"] = "zfs" data["type"] = "jail" except: pass return data
def test_1_in(self): valid = { 'key1': [ 'value', 'value2', 'value;', 1.0, -0xdeadbeef, '0xdeadbeef.1', '0xreadbeef', -1e-10, 1, True, False, True, ] } with open("../tests/basic/1.in", "r") as in1: self.assertEqual(ucl.load(in1.read()), valid)
def hbds_release_branch(self): if self._hbsd_release_branch is not None: return self._hbsd_release_branch if self.fetched is False: raise libiocage.lib.errors.ReleaseNotFetched(name=self.name, logger=self.logger) source_file = f"{self.root_dataset.mountpoint}/etc/hbsd-update.conf" if not os.path.isfile(source_file): raise libiocage.lib.errors.ReleaseUpdateBranchLookup( release_name=self.name, reason=f"{source_file} not found", logger=self.logger) with open(source_file, "r") as f: hbsd_update_conf = ucl.load(f.read()) self._hbsd_release_branch = hbsd_update_conf["branch"] return self._hbsd_release_branch
def test_float(self): data = "a : 1.1" valid = {"a" : 1.1} self.assertEqual(ucl.load(data), valid)
def test_str(self): data = "a : b" valid = { "a" : "b" } self.assertEqual(ucl.load(data), valid)
def test_braced_int(self): data = "{a : 1}" valid = { "a" : 1 } self.assertEqual(ucl.load(data), valid)
def test_none(self): self.assertEqual(ucl.load(None), None)
def test_no_args(self): with self.assertRaises(TypeError): ucl.load()
def test_1_in(self): with open("../tests/basic/1.in", "r") as in1: self.assertEqual(ucl.load(in1.read()), {'key1': 'value'})
def test_comment_ignored(self): self.assertEqual(ucl.load("{/*1*/}"), {})
def test_none(self): r = ucl.load(None) self.assertEqual(r, None)
def test_multi_args(self): with self.assertRaises(TypeError): ucl.load(0,0)
def test_nested_int(self): data = "a : { b : 1 }" valid = { "a" : { "b" : 1 } } self.assertEqual(ucl.load(data), valid)
def test_multi_args(self): self.assertRaises(TypeError, lambda: ucl.load(0,0))
def test_no_args(self): self.assertRaises(TypeError, lambda: ucl.load())
def test_empty_ucl(self): self.assertEqual(ucl.load("{}"), {})
def test_single_square_forward(self): self.assertEqual(ucl.load("["), [])
def test_int(self): r = ucl.load("a : 1") self.assertEqual(ucl.load("a : 1"), { "a" : 1 } )
def test_braced_int(self): self.assertEqual(ucl.load("{a : 1}"), { "a" : 1 } )
def test_nested_int(self): self.assertEqual(ucl.load("a : { b : 1 }"), { "a" : { "b" : 1 } })
def test_null(self): data = "a: null" valid = { "a" : None } self.assertEqual(ucl.load(data), valid)
def test_str(self): self.assertEqual(ucl.load("a : b"), {"a" : "b"})
def test_single_brace(self): self.assertEqual(ucl.load("{"), {})
def test_single_back_brace(self): ucl.load("}")
def test_single_back_brace(self): self.assertEqual(ucl.load("}"), {})
def test_invalid_ucl(self): with self.assertRaisesRegex(ValueError, "unfinished key$"): ucl.load('{ "var"')
def test_float(self): self.assertEqual(ucl.load("a : 1.1"), {"a" : 1.1})
def test_empty_ucl(self): r = ucl.load("{}") self.assertEqual(r, {})
def _read(self) -> dict: import ucl data = dict(ucl.load(open(self.path).read())) if self.logger is not None: self.logger.spam(f"{self._file} was read from {self.path}") return data