-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove unittest and switch to pytest fully
- Loading branch information
1 parent
cef4037
commit 6f10270
Showing
9 changed files
with
159 additions
and
206 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 |
---|---|---|
@@ -1,10 +1,6 @@ | ||
import unittest | ||
import tempfile | ||
|
||
from auto_archiver.core.context import ArchivingContext | ||
|
||
ArchivingContext.reset(full_reset=True) | ||
ArchivingContext.set_tmp_dir(tempfile.gettempdir()) | ||
|
||
if __name__ == '__main__': | ||
unittest.main() | ||
ArchivingContext.set_tmp_dir(tempfile.gettempdir()) |
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,12 @@ | ||
import pytest | ||
from auto_archiver.core.metadata import Metadata | ||
|
||
@pytest.fixture | ||
def make_item(): | ||
def _make_item(url: str, **kwargs) -> Metadata: | ||
item = Metadata().set_url(url) | ||
for key, value in kwargs.items(): | ||
item.set(key, value) | ||
return item | ||
|
||
return _make_item |
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,32 +1,22 @@ | ||
import tempfile | ||
import os | ||
import unittest | ||
|
||
from auto_archiver.databases.csv_db import CSVDb | ||
from auto_archiver.core import Metadata | ||
|
||
|
||
def test_store_item(tmp_path): | ||
"""Tests storing an item in the CSV database""" | ||
|
||
class TestCSVdb(unittest.TestCase): | ||
temp_db = tmp_path / "temp_db.csv" | ||
db = CSVDb({ | ||
"csv_db": {"csv_file": temp_db.as_posix()} | ||
}) | ||
|
||
def setUp(self): | ||
_, temp_db = tempfile.mkstemp(suffix="csv") | ||
self.temp_db = temp_db | ||
item = Metadata().set_url("http://example.com").set_title("Example").set_content("Example content").success("my-archiver") | ||
|
||
def tearDown(self): | ||
os.remove(self.temp_db) | ||
db.done(item) | ||
|
||
def test_store_item(self): | ||
db = CSVDb({ | ||
"csv_db": {"csv_file": self.temp_db} | ||
}) | ||
with open(temp_db, "r", encoding="utf-8") as f: | ||
assert f.read().strip() == f"status,metadata,media\nmy-archiver: success,\"{{'_processed_at': {repr(item.get('_processed_at'))}, 'url': 'http://example.com', 'title': 'Example', 'content': 'Example content'}}\",[]" | ||
|
||
item = Metadata().set_url("http://example.com").set_title("Example").set_content("Example content").success("my-archiver") | ||
|
||
db.done(item) | ||
|
||
with open(self.temp_db, "r") as f: | ||
assert f.read().strip() == f"status,metadata,media\nmy-archiver: success,\"{{'_processed_at': {repr(item.get('_processed_at'))}, 'url': 'http://example.com', 'title': 'Example', 'content': 'Example content'}}\",[]" | ||
|
||
# TODO: csv db doesn't have a fetch method - need to add it (?) | ||
# assert db.fetch(item) == item | ||
# TODO: csv db doesn't have a fetch method - need to add it (?) | ||
# assert db.fetch(item) == item |
Oops, something went wrong.