Skip to content
This repository has been archived by the owner on Jan 14, 2024. It is now read-only.

Commit

Permalink
#66: Improve tests for ArchivePackagingTask
Browse files Browse the repository at this point in the history
  • Loading branch information
blackandred committed Aug 21, 2021
1 parent b1e7957 commit 9ad93fd
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/core/rkd/core/standardlib/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,9 @@ def _create_archive(self, path: str) -> Union[ZipFile, TarFile]:
if self.archive_type == ARCHIVE_TYPE_ZIP:
return ZipFile(temp_path, 'w')
elif self.archive_type == ARCHIVE_TYPE_TARGZ:
return TarFile(temp_path, 'w:gz')
return TarFile.open(temp_path, 'w:gz')
else:
raise Exception('Unknown archive type')

def _make_sure_destination_directory_exists(self, path: str) -> None:
if not self.dry_run:
Expand Down
54 changes: 54 additions & 0 deletions src/core/tests/test_standardlib_io_archivepackagingtask.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,60 @@
class ArchivePackagingTaskTest(FunctionalTestingCase):
backup_stdout = False

def test_packs_into_tar(self):
io = BufferedSystemIO()
task = ArchivePackagingBaseTask()
self.satisfy_task_dependencies(task, io=io)

temp = TempManager()
archive_path = temp.create_tmp_file_path()[0]

# configure
task.archive_path = archive_path
task.archive_type = 'tar+gzip'
task.add('./tests/internal-samples')
task.add(TEST_PATH, 'test.py')

# execute
task.execute(self.mock_execution_context(
task,
{
"--dry-run": False,
"--allow-overwrite": False
},
{}
))

self.assertTrue(os.path.isfile(archive_path))

def test_archive_type_validation_fails_on_unknown_value(self):
"""
Checks if archive_type parameter is validated
:return:
"""

io = BufferedSystemIO()
task = ArchivePackagingBaseTask()
self.satisfy_task_dependencies(task, io=io)

task.archive_path = '/tmp/archive.tar.gz'
task.archive_type = 'tar+wtf'
task.add('./tests/internal-samples')
task.add(TEST_PATH, 'test.py')

with self.assertRaises(Exception) as exc:
task.execute(self.mock_execution_context(
task,
{
"--dry-run": False,
"--allow-overwrite": False
},
{}
))

self.assertIn('Unknown archive type', str(exc.exception))

def test_dry_run_just_prints_messages(self):
"""
Check two things:
Expand Down

0 comments on commit 9ad93fd

Please sign in to comment.