diff --git a/.travis.yml b/.travis.yml index d82702a..305a0d9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,12 +1,13 @@ branches: - only: + only: - master language: python python: - - "3.5" - "3.6" - "3.7" + - "3.8" + - "3.9" cache: - pip @@ -23,6 +24,7 @@ before_script: - pip3 install codecov - pip3 install coveralls - pip3 install codacy-coverage + - pip3 install -r requirements.txt - sudo apt-get update # command to run tests diff --git a/CHANGELOG.md b/CHANGELOG.md index 0fb3fc8..4e1915b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ # CHANGELOG -This is a manually generated log to track changes to the repository for each release. -Each section should include general headers such as **Implemented enhancements** +This is a manually generated log to track changes to the repository for each release. +Each section should include general headers such as **Implemented enhancements** and **Merged pull requests**. Critical items to know are: - renamed commands @@ -12,6 +12,7 @@ and **Merged pull requests**. Critical items to know are: Referenced versions in headers are tagged on Github, in parentheses are for pypi. ## [vxx](https://github.com/urlstechie/urlschecker-python/tree/master) (master) + - accelerate code using asyncio and aiohttp (0.0.23) - updating "whitelist" arguments to exclude (0.0.22) - adding support for dotfiles for a file type (0.0.21) - final regexp needs to again parse away { or } (0.0.20) diff --git a/README.md b/README.md index c04731a..884f995 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@
-[![Build Status](https://travis-ci.com/urlstechie/urlchecker-python.svg?branch=master)](https://travis-ci.com/urlstechie/urlchecker-python) [![Documentation Status](https://readthedocs.org/projects/urlchecker-python/badge/?version=latest)](https://urlchecker-python.readthedocs.io/en/latest/?badge=latest) [![codecov](https://codecov.io/gh/urlstechie/urlchecker-python/branch/master/graph/badge.svg)](https://codecov.io/gh/urlstechie/urlchecker-python) [![Python](https://img.shields.io/badge/python-3.5%20%7C%203.6%20%7C%203.7-blue)](https://www.python.org/doc/versions/) [![CodeFactor](https://www.codefactor.io/repository/github/urlstechie/urlchecker-python/badge)](https://www.codefactor.io/repository/github/urlstechie/urlchecker-python) ![PyPI](https://img.shields.io/pypi/v/urlchecker) [![Downloads](https://pepy.tech/badge/urlchecker)](https://pepy.tech/project/urlchecker) [![License](https://img.shields.io/badge/license-MIT-brightgreen)](https://github.com/urlstechie/urlchecker-python/blob/master/LICENSE) +[![Build Status](https://travis-ci.com/urlstechie/urlchecker-python.svg?branch=master)](https://travis-ci.com/urlstechie/urlchecker-python) [![Documentation Status](https://readthedocs.org/projects/urlchecker-python/badge/?version=latest)](https://urlchecker-python.readthedocs.io/en/latest/?badge=latest) [![codecov](https://codecov.io/gh/urlstechie/urlchecker-python/branch/master/graph/badge.svg)](https://codecov.io/gh/urlstechie/urlchecker-python) [![Python](https://img.shields.io/badge/python-3.5%20|%203.6%20|%203.7%20|%203.8%20|%203.9-blue)](https://www.python.org/doc/versions/) [![CodeFactor](https://www.codefactor.io/repository/github/urlstechie/urlchecker-python/badge)](https://www.codefactor.io/repository/github/urlstechie/urlchecker-python) [![PyPI version](https://badge.fury.io/py/urlchecker.svg)](https://badge.fury.io/py/urlchecker) [![Downloads](https://pepy.tech/badge/urlchecker)](https://pepy.tech/project/urlchecker) [![License](https://img.shields.io/badge/license-MIT-brightgreen)](https://github.com/urlstechie/urlchecker-python/blob/master/LICENSE) # urlchecker-python @@ -10,6 +10,11 @@ and then test for and report broken links. If you are interesting in using this as a GitHub action, see [urlchecker-action](https://github.com/urlstechie/urlchecker-action). There are also container bases available on [quay.io/urlstechie/urlchecker](https://quay.io/repository/urlstechie/urlchecker?tab=tags). +## Module Dependencies +**Versions <= 0.0.22** are built around the [Requests](https://requests.readthedocs.io/en/master/) library whereas +**versions >= 0.0.23** are built around the [asyncio](https://docs.python.org/3/library/asyncio.html) and the [AIOHTTP](https://docs.aiohttp.org/en/stable/) libraries. + + ## Module Documentation A detailed documentation of the code is available under [urlchecker-python.readthedocs.io](https://urlchecker-python.readthedocs.io/en/latest/) @@ -88,7 +93,7 @@ optional arguments: --save SAVE Path to a csv file to save results to. --retry-count RETRY_COUNT retry count upon failure (defaults to 2, one retry). - --timeout TIMEOUT timeout (seconds) to provide to the requests library + --timeout TIMEOUT timeout (minutes) to provide to the aiohttp library (defaults to 5) ``` @@ -121,7 +126,7 @@ $ urlchecker check . save: None timeout: 5 - /tmp/urlchecker-action/README.md + /tmp/urlchecker-action/README.md -------------------------------- https://github.com/urlstechie/urlchecker-action/blob/master/LICENSE https://github.com/r-hub/docs/blob/bc1eac71206f7cb96ca00148dcf3b46c6d25ada4/.github/workflows/pr.yml @@ -152,7 +157,7 @@ https://github.com/SuperKogito/Voice-based-gender-recognition/issues https://github.com/buildtesters/buildtest/blob/v0.9.1/.github/workflows/urlchecker.yml https://github.com/berlin-hack-and-tell/berlinhackandtell.rocks/blob/master/.github/workflows/urlchecker-pr-label.yml - /tmp/urlchecker-action/examples/README.md + /tmp/urlchecker-action/examples/README.md ----------------------------------------- https://github.com/urlstechie/urlchecker-action/releases https://github.com/urlstechie/urlchecker-action/issues @@ -184,7 +189,7 @@ $ urlchecker check --exclude-pattern SuperKogito . save: None timeout: 5 - /tmp/urlchecker-action/README.md + /tmp/urlchecker-action/README.md -------------------------------- https://github.com/urlstechie/urlchecker-action/blob/master/LICENSE https://github.com/urlstechie/urlchecker-action/issues @@ -212,7 +217,7 @@ https://github.com/berlin-hack-and-tell/berlinhackandtell.rocks/actions?query=wo https://github.com/USRSE/usrse.github.io https://github.com/rseng/awesome-rseng/blob/5f5cb78f8392cf10aec2f3952b305ae9611029c2/.github/workflows/urlchecker.yml - /tmp/urlchecker-action/examples/README.md + /tmp/urlchecker-action/examples/README.md ----------------------------------------- https://help.github.com/en/actions/reference/events-that-trigger-workflows https://github.com/urlstechie/urlchecker-action/issues @@ -386,32 +391,32 @@ You can look at `checker.checks`, which is a dictionary of result objects, organized by the filename: ```python -for file_name, result in checker.checks.items(): - print() - print(result) - print("Total Results: %s " % result.count) - print("Total Failed: %s" % len(result.failed)) - print("Total Passed: %s" % len(result.passed)) +for file_name, result in checker.checks.items(): + print() + print(result) + print("Total Results: %s " % result.count) + print("Total Failed: %s" % len(result.failed)) + print("Total Passed: %s" % len(result.passed)) ... UrlCheck:/home/vanessa/Desktop/Code/urlstechie/urlchecker-python/tests/test_files/sample_test_file.md -Total Results: 26 +Total Results: 26 Total Failed: 6 Total Passed: 20 UrlCheck:/home/vanessa/Desktop/Code/urlstechie/urlchecker-python/.pytest_cache/README.md -Total Results: 1 +Total Results: 1 Total Failed: 0 Total Passed: 1 UrlCheck:/home/vanessa/Desktop/Code/urlstechie/urlchecker-python/.eggs/pytest_runner-5.2-py3.7.egg/ptr.py -Total Results: 0 +Total Results: 0 Total Failed: 0 Total Passed: 0 UrlCheck:/home/vanessa/Desktop/Code/urlstechie/urlchecker-python/docs/source/conf.py -Total Results: 3 +Total Results: 3 Total Failed: 0 Total Passed: 3 ``` diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..bb7da88 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +asyncio==3.4.3 +aiohttp==3.7.3 diff --git a/tests/_local_test_config.conf b/tests/_local_test_config.conf index 06cab45..59b5391 100644 --- a/tests/_local_test_config.conf +++ b/tests/_local_test_config.conf @@ -1,5 +1,5 @@ [DEFAULT] git_path_test_value = https://github.com/urlstechie/urlchecker-test-repo -file_types_test_values = .md,.py,.c,.txt +file_types_test_values = .md,.c,.txt exclude_test_urls = https://github.com/SuperKogito/URLs-checker/issues/2,https://github.com/SuperKogito/URLs-checker/issues/3 exclude_test_patterns = https://github.com/SuperKogito/Voice-based-gender-recognition/issues,https://img.shields.io/ diff --git a/tests/test_client_check.py b/tests/test_client_check.py index ba19e73..1f7a237 100644 --- a/tests/test_client_check.py +++ b/tests/test_client_check.py @@ -1,8 +1,28 @@ import os import pytest -import subprocess +import argparse import tempfile +import subprocess import configparser +from urlchecker.client import check + + +def test_client_general(): + # excute scripts + pipe = subprocess.run( + ["urlchecker", "-h"], stdout=subprocess.PIPE, stderr=subprocess.PIPE + ) + assert pipe.stderr.decode("utf-8") == "" + + pipe = subprocess.run( + ["urlchecker", "--help"], stdout=subprocess.PIPE, stderr=subprocess.PIPE + ) + assert pipe.stderr.decode("utf-8") == "" + + pipe = subprocess.run( + ["urlchecker", "--version"], stdout=subprocess.PIPE, stderr=subprocess.PIPE + ) + assert pipe.stderr.decode("utf-8") == "" @pytest.mark.parametrize("config_fname", ["./tests/_local_test_config.conf"]) @@ -10,8 +30,8 @@ @pytest.mark.parametrize("print_all", [False, True]) @pytest.mark.parametrize("force_pass", [False, True]) @pytest.mark.parametrize("rcount", [1, 3]) -@pytest.mark.parametrize("timeout", [3, 5]) -def test_client_general(config_fname, cleanup, print_all, force_pass, rcount, timeout): +@pytest.mark.parametrize("timeout", [5, 7]) +def test_client_check(config_fname, cleanup, print_all, force_pass, rcount, timeout): # init config parser config = configparser.ConfigParser() @@ -101,3 +121,39 @@ def test_client_save(save): if save: if not os.path.exists(output_csv.name): raise AssertionError + + +@pytest.mark.parametrize("config_fname", ["./tests/_local_test_config.conf"]) +def test_client_check_main(config_fname): + + # init config parser + config = configparser.ConfigParser() + config.read(config_fname) + + # init env variables + path = config["DEFAULT"]["git_path_test_value"] + file_types = config["DEFAULT"]["file_types_test_values"] + exclude_urls = config["DEFAULT"]["exclude_test_urls"] + exclude_patterns = config["DEFAULT"]["exclude_test_patterns"] + + # init args + args = argparse.Namespace() + args.path = path + args.branch = "master" + args.subfolder = "test_files" + args.cleanup = True + args.force_pass = True + args.no_print = True + args.file_types = file_types + args.files = "" + args.exclude_urls = "" + args.exclude_patterns = "" + args.exclude_files = "" + args.save = "" + args.retry_count = 1 + args.timeout = 5 + + # excute script + with pytest.raises(SystemExit) as e: + check.main(args=args, extra=[]) + assert e.value.code == 0 diff --git a/tests/test_core_check.py b/tests/test_core_check.py index 4d4426d..7dd58e4 100644 --- a/tests/test_core_check.py +++ b/tests/test_core_check.py @@ -12,7 +12,7 @@ "file_paths", [ ["tests/test_files/sample_test_file.md"], - ["tests/test_files/sample_test_file.py"], + ["tests/test_files/sample_test_file.c"], ["tests/test_files/sample_test_file.rst"], ], ) diff --git a/tests/test_core_fileproc.py b/tests/test_core_fileproc.py index 4cde137..eb4ce7b 100644 --- a/tests/test_core_fileproc.py +++ b/tests/test_core_fileproc.py @@ -31,9 +31,9 @@ def test_check_file_type(file_path, file_types): @pytest.mark.parametrize( "file_path", - ["tests/test_files/sample_test_file.md", "tests/test_files/sample_test_file.py"], + ["tests/test_files/sample_test_file.txt", "tests/test_files/sample_test_file.py"], ) -@pytest.mark.parametrize("file_types", [[".md", ".py"]]) +@pytest.mark.parametrize("file_types", [[".txt", ".py"]]) def test_check_file_type(file_path, file_types): """ test check file types @@ -53,18 +53,18 @@ def test_check_file_type(file_path, file_types): ["tests/test_files/sample_test_file.md", "tests/test_files/sample_test_file.py"], ) @pytest.mark.parametrize( - "white_list_patterns", [["[.py]"], ["[.md]"], ["tests/test_file"]] + "exclude_patterns", [["[.py]"], ["[.md]"], ["tests/test_file"]] ) -def test_include_files(file_path, white_list_patterns): +def test_include_files(file_path, exclude_patterns): """ test if a file should be included based on patterns (using extension for test) """ _, extension = os.path.splitext(file_path) expected = not extension in file_path - result = include_file(file_path, white_list_patterns) + result = include_file(file_path, exclude_patterns) # No files should be included for a global path pattern - if "tests/test_file" in white_list_patterns: + if "tests/test_file" in exclude_patterns: if result: raise AssertionError diff --git a/tests/test_core_urlproc.py b/tests/test_core_urlproc.py index cfcd687..484e148 100644 --- a/tests/test_core_urlproc.py +++ b/tests/test_core_urlproc.py @@ -61,10 +61,10 @@ def test_get_user_agent(): def test_check_response_status_code(): class failedResponse: - status_code = 500 + status = 500 class successResponse: - status_code = 200 + status = 200 # Any failure returns True (indicating a retry is needed) assert not check_response_status_code( diff --git a/tests/test_files/.dotfile b/tests/test_files/.dotfile new file mode 100644 index 0000000..d5cde42 --- /dev/null +++ b/tests/test_files/.dotfile @@ -0,0 +1,4 @@ +https://github.com/urlstechie/urlchecker-action +https://github.com/urlstechie/urlchecker-python +https://github.com/urlstechie/urlstechie.github.io +https://urlstechie.github.io/ diff --git a/tests/test_files/sample_test_file.c b/tests/test_files/sample_test_file.c new file mode 100644 index 0000000..756eed2 --- /dev/null +++ b/tests/test_files/sample_test_file.c @@ -0,0 +1,10 @@ +# This is a test file +include