Skip to content

Commit

Permalink
add tests for checksum_archive. make test_clobber, test_checksum and …
Browse files Browse the repository at this point in the history
…test_checksum_archive platform-independent
  • Loading branch information
benbou8231 committed Apr 25, 2024
1 parent 5b85676 commit 41d2615
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions tests/cli/test_ia_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ def test_clobber(tmpdir_ch):

stdout, stderr = call_cmd(cmd)
assert files_downloaded('nasa') == {'nasa_meta.xml'}
expected_stderr = ('nasa:\n'
' skipping nasa/nasa_meta.xml, file already exists based on length and date.')
prefix = 'nasa:\n'.replace('\n', os.linesep)
filepath = os.path.join('nasa', 'nasa_meta.xml')
expected_stderr = f'{prefix} skipping {filepath}, file already exists based on length and date.'
assert expected_stderr == stderr


Expand All @@ -84,7 +85,31 @@ def test_checksum(tmpdir_ch):

stdout, stderr = call_cmd('ia --insecure download --checksum nasa nasa_meta.xml')
assert files_downloaded('nasa') == {'nasa_meta.xml'}
assert 'nasa:\n skipping nasa/nasa_meta.xml, file already exists based on checksum.' == stderr
prefix = 'nasa:\n'.replace('\n', os.linesep)
filepath = os.path.join('nasa', 'nasa_meta.xml')
assert f'{prefix} skipping {filepath}, file already exists based on checksum.' == stderr


def test_checksum_archive(tmpdir_ch):
call_cmd('ia --insecure download nasa nasa_meta.xml')
assert files_downloaded('nasa') == {'nasa_meta.xml'}

stdout, stderr = call_cmd('ia --insecure download --checksum-archive nasa nasa_meta.xml')
assert files_downloaded('nasa') == {'nasa_meta.xml'}
prefix = 'nasa:\n'.replace('\n', os.linesep)
filepath = os.path.join('nasa', 'nasa_meta.xml')
assert f'{prefix} skipping {filepath}, file already exists based on checksum.' == stderr

assert '_checksum_archive.txt' in files_downloaded('.')
with open(os.path.join('.', '_checksum_archive.txt'), encoding='utf-8') as f:
filepath = os.path.join('nasa', 'nasa_meta.xml')
assert f.read() == f'{filepath}\n'

stdout, stderr = call_cmd('ia --insecure download --checksum-archive nasa nasa_meta.xml')
assert files_downloaded('nasa') == {'nasa_meta.xml'}
prefix = 'nasa:\n'.replace('\n', os.linesep)
filepath = os.path.join('nasa', 'nasa_meta.xml')
assert f'{prefix} skipping {filepath}, file already exists based on checksum_archive.' == stderr


def test_no_directories(tmpdir_ch):
Expand Down

0 comments on commit 41d2615

Please sign in to comment.