-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: move more tests inside packages; clean up
- Loading branch information
Showing
10 changed files
with
176 additions
and
136 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
Empty file.
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,42 @@ | ||
from pathlib import Path | ||
|
||
from ...common import PathIsh, _is_windows as windows | ||
from ...sources.auto import by_path | ||
|
||
|
||
def handled(p: PathIsh) -> bool: | ||
idx, m = by_path(Path(p)) | ||
return idx is not None | ||
# ideally these won't hit libmagic path (would try to open the file and cause FileNotFoundError) | ||
|
||
|
||
def test_filetypes() -> None: | ||
# test media | ||
for ext in 'avi mp4 mp3 webm'.split() + ([] if windows else 'mkv'.split()): | ||
assert handled('file.' + ext) | ||
|
||
# images | ||
for ext in 'gif jpg png jpeg'.split(): | ||
assert handled('file.' + ext) | ||
|
||
# TODO more granual checks that these are ignored? | ||
# binaries | ||
for ext in 'o sqlite'.split() + ([] if windows else 'class jar'.split()): | ||
assert handled('file.' + ext) | ||
|
||
# these might have potentially some links | ||
for ext in [ | ||
'svg', | ||
'pdf', 'epub', 'ps', | ||
'doc', 'ppt', 'xsl', | ||
# seriously, windows doesn't know about docx??? | ||
*([] if windows else 'docx pptx xlsx'.split()), | ||
*([] if windows else 'ods odt rtf'.split()), | ||
] + ([] if windows else 'djvu'.split()): | ||
assert handled('file.' + ext) | ||
|
||
# source code | ||
for ext in 'rs tex el js sh hs pl h py hpp c go css'.split() + ([] if windows else 'java cpp'.split()): | ||
assert handled('file.' + ext) | ||
|
||
assert handled('x.html') |
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
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,43 @@ | ||
from ..common import extract_urls | ||
|
||
|
||
def test_extract_simple() -> None: | ||
lines = """ | ||
I've enjoyed [Chandler Carruth's _There Are No Zero-cost Abstractions_]( | ||
https://www.youtube.com/watch?v=rHIkrotSwcc) very much. | ||
""".strip() | ||
assert set(extract_urls(lines)) == {'https://www.youtube.com/watch?v=rHIkrotSwcc'} | ||
|
||
|
||
def test_extract_2() -> None: | ||
text = '''♂️ Чтобы снизить вероятность ошибиться, важно знать про когнитивные искажения. | ||
Если для вас это новое словосочетание, начните с книжки | ||
"Гарри Поттер и Методы рационального мышления" - http://hpmor.ru/, если вы знакомы с понятием - читайте цепочки на сайтах | ||
lesswrong.ru и lesswrong.com, книжку Даниэля Канемана "Thinking, fast and slow" и канал Пион https://t.me/ontologics | ||
''' | ||
assert set(extract_urls(text)) == {'http://hpmor.ru/', 'lesswrong.ru', 'lesswrong.com', 'https://t.me/ontologics'} | ||
|
||
|
||
def test_extract_md() -> None: | ||
lines = ''' | ||
Hey, I recently implemented a new extension for that [addons.mozilla.org](https://addons.mozilla.org/en-US/firefox/addon/org-grasp-for-org-capture/), [github](https://github.com/karlicoss/grasp), perhaps it could be useful for you! | ||
''' | ||
assert set(extract_urls(lines)) == { | ||
'addons.mozilla.org', | ||
'https://addons.mozilla.org/en-US/firefox/addon/org-grasp-for-org-capture/', | ||
'https://github.com/karlicoss/grasp', | ||
} | ||
|
||
|
||
# just random links to test multiline/whitespace behaviour | ||
def test_extract_3() -> None: | ||
lines = ''' | ||
python.org/one.html ?? https://python.org/two.html some extra text | ||
whatever.org | ||
''' | ||
assert set(extract_urls(lines, syntax='org')) == { | ||
'python.org/one.html', | ||
'https://python.org/two.html', | ||
'whatever.org', | ||
} |
24 changes: 11 additions & 13 deletions
24
tests/test_traverse.py → src/promnesia/tests/test_traverse.py
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 |
---|---|---|
@@ -1,43 +1,41 @@ | ||
from pathlib import Path | ||
from promnesia.common import traverse | ||
from unittest.mock import Mock, patch | ||
from common import DATA | ||
from unittest.mock import patch | ||
|
||
from ..common import traverse | ||
|
||
from .common import get_testdata | ||
|
||
|
||
testDataPath = get_testdata('traverse') | ||
|
||
testDataPath = Path(DATA) / 'traverse' | ||
|
||
# Patch shutil.which so it always returns false (when trying to which fdfind, etc) | ||
# so that it falls back to find | ||
@patch('promnesia.common.shutil.which', return_value=False) | ||
def test_traverse_ignore_find(patched): | ||
def test_traverse_ignore_find(patched) -> None: | ||
''' | ||
traverse() with `find` but ignore some stuff | ||
''' | ||
# act | ||
paths = set(traverse(testDataPath, ignore=['ignoreme.txt', 'ignoreme2'])) | ||
|
||
# assert | ||
assert paths == {testDataPath / 'imhere2/real.txt', testDataPath / 'imhere.txt'} | ||
|
||
|
||
def test_traverse_ignore_fdfind(): | ||
''' | ||
traverse() with `fdfind` but ignore some stuff | ||
''' | ||
# act | ||
paths = set(traverse(testDataPath, ignore=['ignoreme.txt', 'ignoreme2'])) | ||
|
||
# assert | ||
assert paths == {testDataPath / 'imhere.txt', testDataPath / 'imhere2/real.txt'} | ||
|
||
|
||
# TODO: It would be nice to test the implementation directly without having to do this | ||
# weird patching in the future | ||
@patch('promnesia.common._is_windows', new_callable=lambda: True) | ||
def test_traverse_ignore_windows(patched): | ||
def test_traverse_ignore_windows(patched) -> None: | ||
''' | ||
traverse() with python when _is_windows is true but ignore some stuff | ||
''' | ||
# act | ||
paths = set(traverse(testDataPath, ignore=['ignoreme.txt', 'ignoreme2'])) | ||
|
||
# assert | ||
assert paths == {testDataPath / 'imhere.txt', testDataPath / 'imhere2/real.txt'} |
Oops, something went wrong.