From 2c2b2af6140ec8690af5b6d1597ec34494c03d12 Mon Sep 17 00:00:00 2001 From: Unknown Date: Fri, 25 Oct 2019 16:31:03 +0900 Subject: [PATCH] Add download twice test. --- tests/command_download.py | 33 +++++++++++++++++++++++++++++++ tests/command_download_invalid.py | 19 ++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/tests/command_download.py b/tests/command_download.py index e082310a..a62a7f6a 100644 --- a/tests/command_download.py +++ b/tests/command_download.py @@ -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) diff --git a/tests/command_download_invalid.py b/tests/command_download_invalid.py index 706a9627..039bdf72 100644 --- a/tests/command_download_invalid.py +++ b/tests/command_download_invalid.py @@ -8,5 +8,24 @@ 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')