-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This pull request introduces several key changes to the `torah-dl` project, focusing on adding extraction examples, refactoring tests, and updating the documentation. The most important changes include the addition of `ExtractionExample` to the extractors, refactoring the test cases to use a utility function, and updating the README to reflect new installation instructions. ### Addition of Extraction Examples: * [`src/torah_dl/core/models.py`](diffhunk://#diff-bd6461e7b33d76c6137eb081e59f3d0f353d71fff6ae99517a05da4b67414888R18-R33): Introduced the `ExtractionExample` class to represent examples of extractions. * `src/torah_dl/core/extractors/torahanytime.py` and `src/torah_dl/core/extractors/yutorah.py`: Added `EXAMPLES` to the `TorahAnytimeExtractor` and `YutorahExtractor` classes. [[1]](diffhunk://#diff-486bc73189a83c28718dbda4eba49a03447777316f24e3f32b8c66697fcca9b3R17-R43) [[2]](diffhunk://#diff-7cbf568efb6c85f5171fccc0b14a6d968e3ab3d66cbb621ab647838512e89ffbR18-R52) ### Refactoring Tests: * `test/test_core/test_extract.py` and `test/test_core/test_extractors.py`: Refactored test cases to use a new utility function `get_all_the_tests` for generating test parameters dynamically. [[1]](diffhunk://#diff-b6ecd03048aa23fc1bdcdc6b6fd9dda5268afc96384fe3a856b5b2d6a3c4e3f2R2-R9) [[2]](diffhunk://#diff-9377c07ea99c3f7acaea9eccb35d215968f8df9a2f84bafedf9a5097d21ada3bR2-L86) * [`test/test_core/utils.py`](diffhunk://#diff-656800ca19015571b1ea0e3ac99a5ddc024001df33b7dfce45c1c2c2573e28b4R1-R37): Added a new utility function `get_all_the_tests` to dynamically generate test parameters from extractor examples. ### Documentation Update: * [`README.md`](diffhunk://#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5L14-R14): Updated the installation instructions to reflect the new command-line tool usage with `uv`.
- Loading branch information
Showing
7 changed files
with
130 additions
and
97 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
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 |
---|---|---|
@@ -1,86 +1,22 @@ | ||
import pytest | ||
from utils import get_all_the_tests | ||
|
||
from torah_dl.core.exceptions import NetworkError | ||
from torah_dl.core.models import Extractor | ||
|
||
|
||
class TestYutorahExtractor: | ||
from torah_dl.core.extractors import YutorahExtractor | ||
@pytest.mark.parametrize("extractor, url, download_url, title, file_format, valid", get_all_the_tests()) | ||
def test_can_handle(extractor: Extractor, url: str, download_url: str, title: str, file_format: str, valid: bool): | ||
assert extractor.can_handle(url) | ||
|
||
extractor = YutorahExtractor() | ||
|
||
testdata = [ | ||
pytest.param( | ||
"https://www.yutorah.org/lectures/1116616/Praying-for-Rain-and-the-International-Traveler", | ||
"https://download.yutorah.org/2024/986/1116616/praying-for-rain-and-the-international-traveler.mp3", | ||
"Praying for Rain and the International Traveler", | ||
"mp3", | ||
id="main_page", | ||
), | ||
pytest.param( | ||
"https://www.yutorah.org/lectures/1117459/", | ||
"https://download.yutorah.org/2024/986/1117459/davening-with-strep-throat.mp3", | ||
"Davening with Strep Throat", | ||
"mp3", | ||
id="short_link", | ||
), | ||
pytest.param( | ||
"https://www.yutorah.org/lectures/details?shiurid=1117409", | ||
"https://download.yutorah.org/2024/21197/1117409/ketubot-42-dechitat-aveilut-1.mp3", | ||
"Ketubot 42: Dechitat Aveilut (1)", | ||
"mp3", | ||
id="shiurid_link", | ||
), | ||
] | ||
|
||
@pytest.mark.parametrize("url, download_url, title, file_format", testdata) | ||
def test_can_handle(self, url: str, download_url: str, title: str, file_format: str): | ||
assert self.extractor.can_handle(url) | ||
|
||
@pytest.mark.parametrize("url, download_url, title, file_format", testdata) | ||
def test_extract(self, url: str, download_url: str, title: str, file_format: str): | ||
result = self.extractor.extract(url) | ||
assert result.download_url == download_url | ||
assert result.title == title | ||
assert result.file_format == file_format | ||
|
||
def test_extract_invalid_link(self): | ||
@pytest.mark.parametrize("extractor, url, download_url, title, file_format, valid", get_all_the_tests()) | ||
def test_extract(extractor: Extractor, url: str, download_url: str, title: str, file_format: str, valid: bool): | ||
if not valid: | ||
with pytest.raises(NetworkError): | ||
self.extractor.extract("https://www.yutorah.org/lectures/details?shiurid=0000000/") | ||
|
||
|
||
class TestTorahAnytimeExtractor: | ||
from torah_dl.core.extractors import TorahAnytimeExtractor | ||
|
||
extractor = TorahAnytimeExtractor() | ||
|
||
testdata = [ | ||
pytest.param( | ||
"https://torahanytime.com/lectures/335042", | ||
"https://dl.torahanytime.com/mp3/335042--____10_04_2024__ee9743cb-5d09-4ffc-a3e3-1156e10e8944.mp4.mp3", | ||
"Aish Kodesh- Toldot, 5702, When It's Hard to Thank Hashem (2021/22 Series- Enhanced III)", | ||
"mp3", | ||
id="main_page", | ||
), | ||
pytest.param( | ||
"https://MyTAT.me/a335042", | ||
"https://dl.torahanytime.com/mp3/335042--____10_04_2024__ee9743cb-5d09-4ffc-a3e3-1156e10e8944.mp4.mp3", | ||
"Aish Kodesh- Toldot, 5702, When It's Hard to Thank Hashem (2021/22 Series- Enhanced III)", | ||
"mp3", | ||
id="short_link", | ||
), | ||
] | ||
|
||
@pytest.mark.parametrize("url, download_url, title, file_format", testdata) | ||
def test_can_handle(self, url: str, download_url: str, title: str, file_format: str): | ||
assert self.extractor.can_handle(url) | ||
|
||
@pytest.mark.parametrize("url, download_url, title, file_format", testdata) | ||
def test_extract(self, url: str, download_url: str, title: str, file_format: str): | ||
result = self.extractor.extract(url) | ||
extractor.extract(url) | ||
else: | ||
result = extractor.extract(url) | ||
assert result.download_url == download_url | ||
assert result.title == title | ||
assert result.file_format == file_format | ||
|
||
def test_extract_invalid_link(self): | ||
with pytest.raises(NetworkError): | ||
self.extractor.extract("https://torahanytime.com/whatever/0000000") |
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,37 @@ | ||
import importlib | ||
import inspect | ||
from pathlib import Path | ||
|
||
import pytest | ||
|
||
from torah_dl.core.models import Extractor | ||
|
||
|
||
def get_all_the_tests(only_valid: bool = False) -> list[pytest.param]: | ||
extractors_path = Path(__file__).parent.parent.parent / "src" / "torah_dl" / "core" / "extractors" | ||
tests: list[pytest.param] = [] | ||
|
||
for file in extractors_path.glob("*.py"): | ||
if file.stem in ["__init__", "base"]: | ||
continue | ||
|
||
module_path = f"torah_dl.core.extractors.{file.stem}" | ||
module = importlib.import_module(module_path) | ||
|
||
for _, obj in inspect.getmembers(module): | ||
if inspect.isclass(obj) and issubclass(obj, Extractor) and obj != Extractor: | ||
for ex in obj.EXAMPLES: | ||
if only_valid and not ex.valid: | ||
continue | ||
tests.append( | ||
pytest.param( | ||
obj(), | ||
ex.url, | ||
ex.download_url, | ||
ex.title, | ||
ex.file_format, | ||
ex.valid, | ||
id=f"{obj.__name__}.{ex.name}", | ||
) | ||
) | ||
return tests |