Skip to content

Commit

Permalink
Add download twice test.
Browse files Browse the repository at this point in the history
  • Loading branch information
fukatani committed Oct 25, 2019
1 parent 89a33cc commit 4592312
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
33 changes: 33 additions & 0 deletions tests/command_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,36 @@ def snippet_call_download_raises(self, expected_exception, url, is_system=False,
args = get_parser().parse_args(args=args)
with self.assertRaises(expected_exception):
download(args)


def snippet_call_download_twice(self, url1, url2, files, is_system=False, is_silent=False, type='files'):
assert type in 'files' or 'json'
if type == 'json':
files = get_files_from_json(files)

with tests.utils.sandbox([]):
args = ['download', url1]
if is_system:
args += ['--system']
if is_silent:
args += ['--silent']
args = get_parser().parse_args(args=args)
download(args)

args = ['download', url2]
if is_system:
args += ['--system']
if is_silent:
args += ['--silent']
args = get_parser().parse_args(args=args)
# download from url2 should be aborted.
with self.assertRaises(FileExistsError):
download(args)

# check download from url1 is not overwritten
result = {}
if os.path.exists('test'):
for name in os.listdir('test'):
with open(os.path.join('test', name)) as fh:
result[name] = hashlib.md5(fh.buffer.read()).hexdigest()
self.assertEqual(files, result)
20 changes: 20 additions & 0 deletions tests/command_download_invalid.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,25 @@ class DownloadInvalid(unittest.TestCase):
def snippet_call_download_raises(self, *args, **kwargs):
tests.command_download.snippet_call_download_raises(self, *args, **kwargs)

def snippet_call_download_twice(self, *args, **kwargs):
tests.command_download.snippet_call_download_twice(self, *args, **kwargs)

def test_call_download_invalid(self):
self.snippet_call_download_raises(requests.exceptions.InvalidURL, 'https://not_exist_contest.jp/tasks/001_a')

def test_call_download_twice(self):
self.snippet_call_download_twice('https://atcoder.jp/contests/abc114/tasks/abc114_c',
'https://atcoder.jp/contests/abc003/tasks/abc003_4', [
{
"input": "575\n",
"output": "4\n"
},
{
"input": "3600\n",
"output": "13\n"
},
{
"input": "999999999\n",
"output": "26484\n"
},
], type = 'json')

0 comments on commit 4592312

Please sign in to comment.