-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from digitronik/tests
[RFR] Introduce tests for linkstatus
- Loading branch information
Showing
9 changed files
with
169 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
pre-commit | ||
pytest | ||
ruamel.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import os | ||
|
||
import pytest | ||
from ruamel.yaml import safe_load | ||
|
||
BASE_DIR = os.path.dirname(os.path.abspath(__file__)) | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def data(): | ||
with open(os.path.join(BASE_DIR, "data.yaml"), "r") as f: | ||
data = safe_load(f) | ||
return data | ||
|
||
|
||
@pytest.fixture( | ||
params=["file", "files", "directory", "directories", "file-directory"], scope="module" | ||
) | ||
def sources(request): | ||
SOURCES_TYPE = { | ||
"file": [os.path.join(BASE_DIR, "data", "text_file")], | ||
"files": [ | ||
os.path.join(BASE_DIR, "data", "text_file"), | ||
os.path.join(BASE_DIR, "data", "recursive", "recursive_text_file.txt"), | ||
], | ||
"directory": [os.path.join(BASE_DIR, "data")], | ||
"directories": [ | ||
os.path.join(BASE_DIR, "data"), | ||
os.path.join(BASE_DIR, "data", "recursive"), | ||
], | ||
"file-directory": [ | ||
os.path.join(BASE_DIR, "data", "text_file"), | ||
os.path.join(BASE_DIR, "data"), | ||
], | ||
} | ||
return SOURCES_TYPE[request.param] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# Mapping of dir and files as per links and status. | ||
|
||
# Dirs and files with status | ||
data: | ||
parent: | ||
files: | ||
text_file: | ||
'https://github.com/pythonpune/linkstatus': | ||
status: True | ||
line: 'L5' | ||
'http://www.google.com': | ||
status: True, | ||
line: 'L6' | ||
'https://example.com': | ||
status: True, | ||
line: 'L7' | ||
'https://github.com/xyz_foo': | ||
status: False | ||
line: 'L8' | ||
markdown_file.md: | ||
'https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet': | ||
status: True | ||
line: 'L4' | ||
'http://www.google.com': | ||
status: True | ||
line: 'L8' | ||
'https://www.google.com': | ||
status: True | ||
line: 'L10' | ||
'https://github.com/pythonpune/linkstatus': | ||
status: True | ||
line: 'L12' | ||
'http://www.example.com': | ||
status: True | ||
line: 'L24' | ||
'https://github.com/pythonpune/linkcheck': | ||
status: False | ||
line: 'L34' | ||
'https://github.com//pythonpune/': | ||
status: True | ||
line: 'L39' | ||
'http://<hostname>:<port>': | ||
status: False | ||
line: 'L41' | ||
'https://<hostname>:<port>/pages': | ||
status: False | ||
line: 'L43' | ||
recursive: | ||
parent: "data" | ||
files: | ||
recursive_text_file.txt: | ||
'https://github.com/pythonpune/linkstatus': | ||
status: True | ||
line: 'L5' | ||
'http://www.google.com': | ||
status: True, | ||
line: 'L6' | ||
'https://example.com': | ||
status: True, | ||
line: 'L7' | ||
'https://github.com/xyz_foo': | ||
status: False | ||
line: 'L8' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Example recursive text file: | ||
|
||
Note: Line number and status of link mapped in `tests/data/data.yaml` for testing. | ||
|
||
1. linkstatus: https://github.com/pythonpune/linkstatus | ||
2. google: http://www.google.com | ||
3. example: https://example.com | ||
4. broken: https://github.com/xyz_foo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import os | ||
|
||
import pytest | ||
|
||
from linkstatus.linkstatus import all_files | ||
|
||
|
||
@pytest.mark.parametrize("recursive", [True, False], ids=["recursive", "non-recursive"]) | ||
def test_all_files(sources, recursive): | ||
collected_files = all_files(sources, recursive=recursive) | ||
expected_files = [] | ||
|
||
for source_entity in sources: | ||
if os.path.isfile(source_entity): | ||
expected_files.append(source_entity) | ||
else: | ||
inside_entities = [os.path.join(source_entity, e) for e in os.listdir(source_entity)] | ||
inside_files = [f for f in inside_entities if os.path.isfile(f)] | ||
|
||
if recursive: | ||
for d in [d for d in inside_entities if os.path.isdir(d) and "__" not in d]: | ||
files = [ | ||
os.path.join(d, f) | ||
for f in os.listdir(d) | ||
if os.path.isfile(os.path.join(d, f)) | ||
] | ||
inside_files.extend(files) | ||
expected_files.extend(inside_files) | ||
|
||
assert set(collected_files) == set(expected_files) |