def test_ignore_wildcard_resources(self): with patch("%s.open" % built_in_entry, mock_open(read_data="*.log")), \ patch('os.path.isfile', create=True) as mock_isfile: mock_isfile.__return_value__ = True cf_ignore = CfIgnore('/some/path') self.assertTrue(cf_ignore.is_entry_ignored("toto.log")) self.assertTrue( cf_ignore.is_entry_ignored("/some/other/path/toto.log"))
def _load_all_resources(top_directory: str) -> dict: application_items = {} cf_ignore = CfIgnore(top_directory) for directory, file_names in FileHelper.walk(top_directory): for file_name in file_names: relative_file_location = os.path.join(directory, file_name) if not cf_ignore.is_entry_ignored(relative_file_location): absolute_file_location = os.path.join( top_directory, relative_file_location) application_items[relative_file_location] = dict( sha1=FileHelper.sha1(absolute_file_location), size=FileHelper.size(absolute_file_location), mode=FileHelper.mode(absolute_file_location)) return application_items
def test_open_cfignore_file(self): with patch("%s.open" % built_in_entry, mock_open(read_data="*.log")) as mock_file, \ patch('os.path.isfile', create=True) as mock_isfile: mock_isfile.__return_value__ = True application_path = '/some/path' CfIgnore(application_path) mock_file.assert_called_with( os.path.join(application_path, '.cfignore'), 'r')
def test_open_cfignore_file(self): with patch("builtins.open", mock_open(read_data="*.log")) as mock_file, patch( "os.path.isfile", create=True) as mock_isfile: mock_isfile.__return_value__ = True application_path = "/some/path" CfIgnore(application_path) mock_file.assert_called_with( os.path.join(application_path, ".cfignore"), "r")
def test_ignore_directory(self): with patch("%s.open" % built_in_entry, mock_open(read_data="ignored/directory/")), \ patch('os.path.isfile', create=True) as mock_isfile: mock_isfile.__return_value__ = True cf_ignore = CfIgnore('/some/path') self.assertTrue( cf_ignore.is_entry_ignored("ignored/directory/resource.file")) self.assertTrue( cf_ignore.is_entry_ignored("/ignored/directory/resource.file")) self.assertTrue( cf_ignore.is_entry_ignored( "/some/sub/directory/containing/ignored/directory/resource.file" )) # File in fact self.assertFalse(cf_ignore.is_entry_ignored('/ignored/directory'))
def test_ignore_file_with_directory(self): with patch( "builtins.open", mock_open(read_data="ignored/directory/resource.file")), patch( "os.path.isfile", create=True) as mock_isfile: mock_isfile.__return_value__ = True cf_ignore = CfIgnore("/some/path") self.assertTrue( cf_ignore.is_entry_ignored("ignored/directory/resource.file")) self.assertTrue( cf_ignore.is_entry_ignored("/ignored/directory/resource.file")) self.assertTrue( cf_ignore.is_entry_ignored( "/some/sub/directory/containing/ignored/directory/resource.file" )) # File in fact self.assertFalse( cf_ignore.is_entry_ignored("ignored/resource.file"))