示例#1
0
文件: test_load.py 项目: 0mp/freebsd
 def test_boolean(self):
     data = (
         "a : True;" \
         "b : False"
     )
     valid = { "a" : True, "b" : False }
     self.assertEqual(ucl.load(data), valid)
示例#2
0
    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)
示例#3
0
 def test_boolean(self):
     totest = (
         "a : True;" \
         "b : False"
     )
     correct = {"a": True, "b": False}
     self.assertEqual(ucl.load(totest), correct)
示例#4
0
 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)
示例#5
0
 def test_boolean(self):
     totest = (
         "a : True;" \
         "b : False"
     )
     correct = {"a" : True, "b" : False}
     self.assertEqual(ucl.load(totest), correct)
示例#6
0
    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)
示例#7
0
 def test_boolean(self):
     data = (
         "a : True;" \
         "b : False"
     )
     valid = { "a" : True, "b" : False }
     self.assertEqual(ucl.load(data), valid)
示例#8
0
文件: test_load.py 项目: 0mp/freebsd
 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)
示例#9
0
 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)
示例#10
0
    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)
示例#11
0
    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
示例#12
0
 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)
示例#13
0
    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
示例#14
0
 def test_float(self):
     data  = "a : 1.1"
     valid = {"a" : 1.1}
     self.assertEqual(ucl.load(data), valid)
示例#15
0
 def test_str(self):
     data  = "a : b"
     valid = { "a" : "b" }
     self.assertEqual(ucl.load(data), valid)
示例#16
0
 def test_braced_int(self):
     data  = "{a : 1}"
     valid = { "a" : 1 }
     self.assertEqual(ucl.load(data), valid)
示例#17
0
 def test_none(self):
     self.assertEqual(ucl.load(None), None)
示例#18
0
 def test_no_args(self):
     with self.assertRaises(TypeError):
         ucl.load()
示例#19
0
 def test_1_in(self):
     with open("../tests/basic/1.in", "r") as in1:
         self.assertEqual(ucl.load(in1.read()), {'key1': 'value'})
示例#20
0
 def test_comment_ignored(self):
     self.assertEqual(ucl.load("{/*1*/}"), {})
示例#21
0
 def test_none(self):
     r = ucl.load(None)
     self.assertEqual(r, None)
示例#22
0
 def test_multi_args(self):
     with self.assertRaises(TypeError):
         ucl.load(0,0)
示例#23
0
文件: test_load.py 项目: 0mp/freebsd
 def test_nested_int(self):
     data  = "a : { b : 1 }"
     valid = { "a" : { "b" : 1 } }
     self.assertEqual(ucl.load(data), valid)
示例#24
0
文件: test_load.py 项目: 0mp/freebsd
 def test_str(self):
     data  = "a : b"
     valid = { "a" : "b" }
     self.assertEqual(ucl.load(data), valid)
示例#25
0
 def test_multi_args(self):
     self.assertRaises(TypeError, lambda: ucl.load(0,0))
示例#26
0
 def test_no_args(self):
     self.assertRaises(TypeError, lambda: ucl.load())
示例#27
0
 def test_empty_ucl(self):
     self.assertEqual(ucl.load("{}"), {})
示例#28
0
 def test_single_square_forward(self):
     self.assertEqual(ucl.load("["), [])
示例#29
0
 def test_int(self):
     r = ucl.load("a : 1")
     self.assertEqual(ucl.load("a : 1"), { "a" : 1 } )
示例#30
0
文件: test_load.py 项目: 0mp/freebsd
 def test_float(self):
     data  = "a : 1.1"
     valid = {"a" : 1.1}
     self.assertEqual(ucl.load(data), valid)
示例#31
0
 def test_braced_int(self):
     self.assertEqual(ucl.load("{a : 1}"), { "a" : 1 } )
示例#32
0
文件: test_load.py 项目: 0mp/freebsd
 def test_braced_int(self):
     data  = "{a : 1}"
     valid = { "a" : 1 }
     self.assertEqual(ucl.load(data), valid)
示例#33
0
 def test_nested_int(self):
     self.assertEqual(ucl.load("a : { b : 1 }"), { "a" : { "b" : 1 } })
示例#34
0
文件: test_load.py 项目: 0mp/freebsd
 def test_null(self):
     data  = "a: null"
     valid = { "a" : None }
     self.assertEqual(ucl.load(data), valid)
示例#35
0
 def test_str(self):
     self.assertEqual(ucl.load("a : b"), {"a" : "b"})
示例#36
0
 def test_null(self):
     data  = "a: null"
     valid = { "a" : None }
     self.assertEqual(ucl.load(data), valid)
示例#37
0
 def test_multi_args(self):
     with self.assertRaises(TypeError):
         ucl.load(0,0)
示例#38
0
 def test_nested_int(self):
     data  = "a : { b : 1 }"
     valid = { "a" : { "b" : 1 } }
     self.assertEqual(ucl.load(data), valid)
示例#39
0
 def test_single_brace(self):
     self.assertEqual(ucl.load("{"), {})
示例#40
0
 def test_no_args(self):
     with self.assertRaises(TypeError):
         ucl.load()
示例#41
0
 def test_single_back_brace(self):
     ucl.load("}")
示例#42
0
文件: test_load.py 项目: 0mp/freebsd
 def test_none(self):
     self.assertEqual(ucl.load(None), None)
示例#43
0
 def test_single_square_forward(self):
     self.assertEqual(ucl.load("["), [])
示例#44
0
 def test_single_back_brace(self):
     self.assertEqual(ucl.load("}"), {})
示例#45
0
 def test_invalid_ucl(self):
     with self.assertRaisesRegex(ValueError, "unfinished key$"):
         ucl.load('{ "var"')
示例#46
0
 def test_invalid_ucl(self):
     with self.assertRaisesRegex(ValueError, "unfinished key$"):
         ucl.load('{ "var"')
示例#47
0
 def test_comment_ignored(self):
     self.assertEqual(ucl.load("{/*1*/}"), {})
示例#48
0
 def test_float(self):
     self.assertEqual(ucl.load("a : 1.1"), {"a" : 1.1})
示例#49
0
文件: test_load.py 项目: 0mp/freebsd
 def test_empty_ucl(self):
     self.assertEqual(ucl.load("{}"), {})
示例#50
0
 def test_empty_ucl(self):
     r = ucl.load("{}")
     self.assertEqual(r, {})
示例#51
0
 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