From fb42a66bf718098c382d6fb50f24f1c60a13f6e7 Mon Sep 17 00:00:00 2001 From: Cody Logan Date: Fri, 14 Dec 2018 11:56:01 -0800 Subject: Add some tests with pytest Can be run with `pytest` (if installed) or `python setup.py test` --- test/test_wikiget.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 test/test_wikiget.py (limited to 'test') diff --git a/test/test_wikiget.py b/test/test_wikiget.py new file mode 100644 index 0000000..981d640 --- /dev/null +++ b/test/test_wikiget.py @@ -0,0 +1,45 @@ +"""wikiget +Simple wget clone for downloading files from Wikimedia sites. +Copyright (C) 2018 Cody Logan; licensed GPLv3+ +SPDX-License-Identifier: GPL-3.0-or-later +""" + +from wikiget import wikiget + + +def test_invalid_site_input(): + invalid_input = ["example.com", "vim.wikia.com", + "en.wikipedia.com", "en.wikimpedia.org"] + for i in invalid_input: + site_match = wikiget.valid_site(i) + assert site_match is None + + +def test_valid_site_input(): + valid_input = ["en.wikipedia.org", "commons.wikimedia.org", + "de.wikipedia.org", "meta.wikimedia.org"] + for i in valid_input: + site_match = wikiget.valid_site(i) + assert site_match is not None + + +def test_file_regex(): + i = "File:Example.jpg" + file_match = wikiget.valid_file(i) + assert file_match.group(0) + assert file_match.group(1) == "File:" + assert file_match.group(2) == "Example.jpg" + + +def test_invalid_file_input(): + invalid_input = ["file:example", "example"] + for i in invalid_input: + file_match = wikiget.valid_file(i) + assert file_match is None + + +def test_valid_file_input(): + valid_input = ["example.jpg", "file:example.jpg", "example.file-01.jpg"] + for i in valid_input: + file_match = wikiget.valid_file(i) + assert file_match is not None -- cgit v1.2.3