Merge pull request #352 from cdvv7788/pytest-setup

This commit is contained in:
Nick Sweeting 2020-07-03 18:06:38 -04:00 committed by GitHub
commit 1866da3f8a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 71 additions and 0 deletions

25
.github/workflows/test.yml vendored Normal file
View file

@ -0,0 +1,25 @@
name: Test workflow
on: [push]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
with:
fetch-depth: 1
- name: Set up Python 3.7
uses: actions/setup-python@v1
with:
python-version: 3.7
architecture: x64
- name: Install dependencies
run: |
pip install -e .[dev]
- name: Test with pytest
run: |
pytest -s

View file

@ -64,6 +64,7 @@ setuptools.setup(
"sphinx",
"sphinx-rtd-theme",
"recommonmark",
"pytest",
],
# 'redis': ['redis', 'django-redis'],
# 'pywb': ['pywb', 'redis'],

40
tests/test_init.py Normal file
View file

@ -0,0 +1,40 @@
# archivebox init
# archivebox add
import os
import subprocess
from pathlib import Path
import json
import pytest
@pytest.fixture
def process(tmp_path):
os.chdir(tmp_path)
process = subprocess.run(['archivebox', 'init'], capture_output=True)
return process
def test_init(tmp_path, process):
assert "Initializing a new ArchiveBox collection in this folder..." in process.stdout.decode("utf-8")
def test_update(tmp_path, process):
os.chdir(tmp_path)
update_process = subprocess.run(['archivebox', 'init'], capture_output=True)
assert "Updating existing ArchiveBox collection in this folder" in update_process.stdout.decode("utf-8")
def test_add_link(tmp_path, process):
os.chdir(tmp_path)
add_process = subprocess.run(['archivebox', 'add', 'http://example.com'], capture_output=True)
archived_item_path = list(tmp_path.glob('archive/**/*'))[0]
assert "index.json" in [x.name for x in archived_item_path.iterdir()]
with open(archived_item_path / "index.json", "r") as f:
output_json = json.load(f)
assert "IANA — IANA-managed Reserved Domains" == output_json['history']['title'][0]['output']
with open(tmp_path / "index.html", "r") as f:
output_html = f.read()
assert "IANA — IANA-managed Reserved Domains" in output_html

5
tests/test_util.py Normal file
View file

@ -0,0 +1,5 @@
from archivebox import util
def test_download_url_downloads_content():
text = util.download_url("https://example.com")
assert "Example Domain" in text