Prv8 Shell
Server : Apache
System : Linux server.mata-lashes.com 3.10.0-1160.90.1.el7.x86_64 #1 SMP Thu May 4 15:21:22 UTC 2023 x86_64
User : matalashes ( 1004)
PHP Version : 8.1.29
Disable Function : NONE
Directory :  /proc/17567/root/usr/src/cloud-init/tests/unittests/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //proc/17567/root/usr/src/cloud-init/tests/unittests/test_pathprefix2dict.py
# This file is part of cloud-init. See LICENSE file for license information.

import shutil
import tempfile

from cloudinit import util
from tests.unittests.helpers import TestCase, populate_dir


class TestPathPrefix2Dict(TestCase):
    def setUp(self):
        super(TestPathPrefix2Dict, self).setUp()
        self.tmp = tempfile.mkdtemp()
        self.addCleanup(shutil.rmtree, self.tmp)

    def test_required_only(self):
        dirdata = {"f1": b"f1content", "f2": b"f2content"}
        populate_dir(self.tmp, dirdata)

        ret = util.pathprefix2dict(self.tmp, required=["f1", "f2"])
        self.assertEqual(dirdata, ret)

    def test_required_missing(self):
        dirdata = {"f1": b"f1content"}
        populate_dir(self.tmp, dirdata)
        kwargs = {"required": ["f1", "f2"]}
        self.assertRaises(ValueError, util.pathprefix2dict, self.tmp, **kwargs)

    def test_no_required_and_optional(self):
        dirdata = {"f1": b"f1c", "f2": b"f2c"}
        populate_dir(self.tmp, dirdata)

        ret = util.pathprefix2dict(
            self.tmp, required=None, optional=["f1", "f2"]
        )
        self.assertEqual(dirdata, ret)

    def test_required_and_optional(self):
        dirdata = {"f1": b"f1c", "f2": b"f2c"}
        populate_dir(self.tmp, dirdata)

        ret = util.pathprefix2dict(self.tmp, required=["f1"], optional=["f2"])
        self.assertEqual(dirdata, ret)


# vi: ts=4 expandtab

haha - 2025