From 071731a36eeceae7ee6bac2b6f57fc2f0c414900 Mon Sep 17 00:00:00 2001 From: Vitor Falcao Date: Sun, 9 Jun 2019 13:34:07 -0300 Subject: [PATCH] Initial creation of tests --- cfaster/__main__.py | 2 +- tests/__init__.py | 0 tests/test_main_cmd.py | 12 ++++++++++ tests/test_scrape_cmd.py | 50 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 tests/__init__.py create mode 100644 tests/test_main_cmd.py create mode 100644 tests/test_scrape_cmd.py diff --git a/cfaster/__main__.py b/cfaster/__main__.py index 44c10a6..78e2b7e 100644 --- a/cfaster/__main__.py +++ b/cfaster/__main__.py @@ -22,7 +22,7 @@ def set_log_levels(level=logging.WARNING): @group() @option('-v', '--verbose', is_flag=True, help='Output INFO level logs.') -@version_option(__version__, message='v%(version)s') +@version_option(__version__, message='%(version)s') def main_cmd(verbose): if verbose: set_log_levels(logging.INFO) diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_main_cmd.py b/tests/test_main_cmd.py new file mode 100644 index 0000000..a50cf94 --- /dev/null +++ b/tests/test_main_cmd.py @@ -0,0 +1,12 @@ +import re +from click.testing import CliRunner +from cfaster.__main__ import main_cmd + +runner = CliRunner() + +def test_version(): + result = runner.invoke(main_cmd, ['--version']) + reg = r'\d+\.\d+\.\d+' + match = re.match(reg, result.output) + assert result.exit_code == 0 + assert match is not None diff --git a/tests/test_scrape_cmd.py b/tests/test_scrape_cmd.py new file mode 100644 index 0000000..3f9f130 --- /dev/null +++ b/tests/test_scrape_cmd.py @@ -0,0 +1,50 @@ +from click.testing import CliRunner +from cfaster.__main__ import scrape + +runner = CliRunner() + +invalid_urls = [ + 'http://domain.com/problem', + 'https://domain.com/problem', + 'domain.com', + 'https://codeforces.com', + 'https://codeforces.com/contests', + 'sadaddsg.sda..sad', + 'www.codeforces.com/sad/dasdas/problem/A', + 'www.codeforces.com', +] + +valid_urls = [ + 'https://codeforces.com/contest/1172/problem/A', + 'https://codeforces.com/contest/1172/problem/C1', + 'https://codeforces.com/contest/1172/problem/E', + 'https://codeforces.com/contest/1174/problem/B', + 'https://codeforces.com/contest/1174/problem/D', +] + +def test_no_url(): + result = runner.invoke(scrape) + assert result.exit_code == 2 + +def test_invalid_urls(): + for invalid_url in invalid_urls: + result = runner.invoke(scrape, invalid_url) + assert result.exit_code != 0 + +def test_verbose_scrape(): + pass + +def test_valid_url(): + pass + +def test_count_inputs(): + pass + +def test_count_outputs(): + pass + +def test_inputs(): + pass + +def test_outputs(): + pass