added tests
This commit is contained in:
parent
31d0da62f2
commit
4431f7820a
3 changed files with 57 additions and 4 deletions
14
readme.md
14
readme.md
|
@ -33,21 +33,27 @@ The name comes from the [D&D 5e spell](https://roll20.net/compendium/dnd5e/Knock
|
|||
|
||||
There are no userspace runtime dependencies.
|
||||
|
||||
## Building & Contributing
|
||||
## Contributing
|
||||
|
||||
Install [Nix](https://github.com/NixOS/nix) if you don't have it. [Enable flakes](https://nixos.wiki/wiki/Flakes) if you haven't. Run
|
||||
Install [Nix](https://github.com/NixOS/nix) if you don't have it. Enable [flakes](https://nixos.wiki/wiki/Flakes) if you haven't.
|
||||
|
||||
### Building
|
||||
|
||||
```
|
||||
nix build
|
||||
```
|
||||
|
||||
to build and
|
||||
### Updating
|
||||
|
||||
```
|
||||
nix flake update
|
||||
```
|
||||
|
||||
to update libraries.
|
||||
### Testing
|
||||
|
||||
```
|
||||
./tests/test.py
|
||||
```
|
||||
|
||||
Test books can be found [here](https://www.adobe.com/solutions/ebook/digital-editions/sample-ebook-library.html).
|
||||
|
||||
|
|
1
tests/.gitignore
vendored
Normal file
1
tests/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
workspace
|
46
tests/test.py
Executable file
46
tests/test.py
Executable file
|
@ -0,0 +1,46 @@
|
|||
#! /usr/bin/env nix-shell
|
||||
#! nix-shell -i python3 -p python3 python310Packages.beautifulsoup4 python310Packages.requests
|
||||
|
||||
from bs4 import BeautifulSoup
|
||||
from urllib.parse import urlparse
|
||||
from pathlib import Path
|
||||
import requests, sys, subprocess, shutil, os
|
||||
|
||||
knock_path = Path(__file__).parent.parent.joinpath("result/bin/knock")
|
||||
workspace = Path(__file__).parent.joinpath("workspace")
|
||||
|
||||
if workspace.exists():
|
||||
shutil.rmtree(workspace)
|
||||
workspace.mkdir()
|
||||
|
||||
html = requests \
|
||||
.get("https://www.adobe.com/solutions/ebook/digital-editions/sample-ebook-library.html") \
|
||||
.text
|
||||
soup = BeautifulSoup(html, 'html.parser')
|
||||
|
||||
links = []
|
||||
for a_tag in soup.find_all('a'):
|
||||
if a_tag.string != "Download eBook":
|
||||
continue
|
||||
if not urlparse(a_tag.get("href")).path.endswith(".acsm"):
|
||||
continue
|
||||
|
||||
links.append(a_tag.get("href"))
|
||||
|
||||
for i, link in enumerate(links):
|
||||
i = str(i)
|
||||
print("Testing URL #" + i + ":\n" + link)
|
||||
file = workspace.joinpath(i + ".acsm")
|
||||
|
||||
r = requests.get(link)
|
||||
open(file, "wb").write(r.content)
|
||||
|
||||
result = subprocess.run([knock_path, file])
|
||||
|
||||
if result.returncode != 0:
|
||||
print("Failed")
|
||||
sys.exit()
|
||||
|
||||
print("Success\n---")
|
||||
|
||||
print("All tests passed")
|
Loading…
Reference in a new issue