Esempio n. 1
0
def test_nonempty_directory_with_extensions():
    with tempfile.TemporaryDirectory() as mydir:
        __a = Path(mydir, 'a.txt')
        __b = Path(mydir, 'b.jsonnet')
        __c = Path(mydir, 'c.conf')
        __a.touch()
        __b.touch()
        __c.touch()

        files = fs.files_with_extensions(mydir, '.jsonnet')
        assert files == (['b', str(__b)], )

        files = fs.files_with_extensions(mydir, '.jsonnet', '.conf')
        assert files == (['b', str(__b)], ['c', str(__c)])
Esempio n. 2
0
    def load_all_channels(self):
        """
        Load all channel configurations inside the stored channel-configuration directory.

        Any cached configurations will be dropped prior to reloading.
        """
        if self.channels:
            self.channels = {}
            self.logger.info(
                "All channel configurations have been removed and are being reloaded."
            )

        self.logger.info(
            f"Loading channel configs from:{self.channel_config_dir}")

        files = fs.files_with_extensions(self.channel_config_dir, ".conf",
                                         ".jsonnet")
        for channel_name, full_path in files:
            # Load only the channels that are not already in memory
            if channel_name in self.channels:
                self.logger.info(
                    f"Already loaded a channel called '{channel_name}'. Skipping {full_path}"
                )
                continue

            success, result = self._load_channel(channel_name, full_path)
            if not success:
                self.logger.error(f"CHANNEL LOAD FAILURE: {result}")
Esempio n. 3
0
    def load_all_channels(self):
        '''
        Load all channel configurations inside the stored channel-configuration directory.

        Any cached configurations will be dropped prior to reloading.
        '''
        if self.channels:
            self.channels = {}
            self.logger.info(
                "All channel configurations have been removed and are being reloaded."
            )

        files = fs.files_with_extensions(self.channel_config_dir, '.conf',
                                         '.jsonnet')
        for channel_name, full_path in files:
            # Load only the channels that are not already in memory
            if channel_name in self.channels:
                self.logger.info(
                    f"Already loaded a channel called '{channel_name}', skipping {full_path}"
                )
                continue

            success, result = self._load_channel(channel_name, full_path)
            if not success:
                self.logger.error(result)
Esempio n. 4
0
def test_nonempty_directory_with_extensions():
    with tempfile.TemporaryDirectory() as mydir:
        __a = Path(mydir, "a.txt")
        __b = Path(mydir, "b.jsonnet")
        __c = Path(mydir, "c.conf")
        __d = Path(mydir, "somedir")
        __a.touch()
        __b.touch()
        __c.touch()
        __d.mkdir()

        files = fs.files_with_extensions(mydir, ".jsonnet")
        assert files == (["b", str(__b)], )

        files = fs.files_with_extensions(mydir, ".jsonnet", ".conf")
        assert files == (["b", str(__b)], ["c", str(__c)])
Esempio n. 5
0
def test_non_real_directory():
    with pytest.raises(FileNotFoundError):
        fs.files_with_extensions('/this/dir/isnt/real')
Esempio n. 6
0
def test_nonempty_directory():
    with tempfile.TemporaryDirectory() as mydir:
        __a = Path(mydir, 'a.txt')
        __a.touch()
        files = fs.files_with_extensions(mydir)
        assert files == (['a', str(__a)], )
Esempio n. 7
0
def test_empty_directory():
    with tempfile.TemporaryDirectory() as mydir:
        files = fs.files_with_extensions(mydir)
        assert len(files) == 0
Esempio n. 8
0
def test_empty_directory():
    mydir = tempfile.TemporaryDirectory()
    files = fs.files_with_extensions(mydir.name)
    assert len(files) == 0