Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def extraction_test(self, archive):
"""Generic test for extraction of all types of archives"""
EXTRACT_DIR = os.path.join(os.getcwd(), 'dir')
EXTRACTED_FILE = os.path.join(EXTRACT_DIR, self.ARCHIVED_FILE)
archive = Archive(archive)
archive.extract_archive(EXTRACT_DIR)
# check if the dir was created
assert os.path.isdir(EXTRACT_DIR)
# check if the file was extracted
assert os.path.isfile(EXTRACTED_FILE)
# check the content
with open(EXTRACTED_FILE) as f:
assert f.read().strip() == self.ARCHIVED_FILE_CONTENT
def _extract_sources(self, archive, dir_name):
archive = Archive(archive)
archive.extract_archive(dir_name)
def test_find_pythoon(self):
assert PathHelper.find_first_dir_with_file(
"dir1", "pythooon") == os.path.abspath(
os.path.dirname(self.files[4]))
assert PathHelper.find_first_dir_with_file(
os.path.curdir, "py*n") == os.path.abspath(os.path.dirname(self.files[4]))
assert PathHelper.find_first_dir_with_file(
"dir1/bar", "pythooon") is None
def test_find_ffile(self):
assert PathHelper.find_first_dir_with_file(
"dir1", "*le") == os.path.abspath(
os.path.dirname(self.files[9]))
assert PathHelper.find_first_dir_with_file(
"dir1", "ff*") == os.path.abspath(
os.path.dirname(self.files[8]))
assert PathHelper.find_first_dir_with_file(
"dir1/foo", "ff*") is None
def test_find_ffile(self):
assert PathHelper.find_first_dir_with_file(
"dir1", "*le") == os.path.abspath(
os.path.dirname(self.files[9]))
assert PathHelper.find_first_dir_with_file(
"dir1", "ff*") == os.path.abspath(
os.path.dirname(self.files[8]))
assert PathHelper.find_first_dir_with_file(
"dir1/foo", "ff*") is None
def test_find_pythoon(self):
assert PathHelper.find_first_dir_with_file(
"dir1", "pythooon") == os.path.abspath(
os.path.dirname(self.files[4]))
assert PathHelper.find_first_dir_with_file(
os.path.curdir, "py*n") == os.path.abspath(os.path.dirname(self.files[4]))
assert PathHelper.find_first_dir_with_file(
"dir1/bar", "pythooon") is None
def test_find_file(self):
assert PathHelper.find_first_dir_with_file(
"dir1", "file") == os.path.abspath(
os.path.dirname(self.files[9]))
assert PathHelper.find_first_dir_with_file(
os.path.curdir, "file") == os.path.abspath(os.path.dirname(self.files[0]))
assert PathHelper.find_first_dir_with_file(
"dir1/baz", "file") is None
def test_find_ffile(self):
assert PathHelper.find_first_file(
"dir1", "*le") == os.path.abspath(self.files[9])
assert PathHelper.find_first_file(
"dir1", "ff*") == os.path.abspath(self.files[8])
assert PathHelper.find_first_file("dir1/foo", "ff*") is None
def test_find_ffile(self):
assert PathHelper.find_first_file(
"dir1", "*le") == os.path.abspath(self.files[9])
assert PathHelper.find_first_file(
"dir1", "ff*") == os.path.abspath(self.files[8])
assert PathHelper.find_first_file("dir1/foo", "ff*") is None
def test_find_with_recursion(self):
assert PathHelper.find_first_file(os.path.curdir, "*.spec", 0) is None
assert PathHelper.find_first_file(os.path.curdir, "*.spec", 1) is None
assert PathHelper.find_first_file(os.path.curdir, "*.spec", 2) is None
assert PathHelper.find_first_file(os.path.curdir, "*.spec", 3) is None
assert PathHelper.find_first_file(os.path.curdir, "*.spec", 4) == os.path.abspath(self.files[-1])