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)])
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}")
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)
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)])
def test_non_real_directory(): with pytest.raises(FileNotFoundError): fs.files_with_extensions('/this/dir/isnt/real')
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)], )
def test_empty_directory(): with tempfile.TemporaryDirectory() as mydir: files = fs.files_with_extensions(mydir) assert len(files) == 0
def test_empty_directory(): mydir = tempfile.TemporaryDirectory() files = fs.files_with_extensions(mydir.name) assert len(files) == 0