Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
BurnzZ committed Jul 4, 2024
1 parent f2b860e commit 142ee84
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: tox

on:
pull_request:
push:
branches: [ main ]

jobs:
test:

runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- python-version: "3.8"
- python-version: "3.9"
- python-version: "3.10"
- python-version: "3.11"
- python-version: "3.12"
- python-version: "3.12"

steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install tox
- name: tox
run: |
tox -e ${{ matrix.toxenv || 'py' }}
Empty file added tests/__init__.py
Empty file.
34 changes: 34 additions & 0 deletions tests/test_rules.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import json

from url_matcher import Patterns

from duplicate_url_discarder_rules import RULE_PATHS


def test_rule_validity():
for path in RULE_PATHS:
try:
with open(path, "r") as f:
data = json.loads(f.read())
except Exception as e:
raise ValueError(f"Something went wrong when reading '{path}': {str(e)}.")

assert isinstance(
data, list
), f"The rules should be a list: '{path}'. Got {type(data)}."

for rule in data:
order = rule.get("order")
assert order is not None, path
assert isinstance(order, int), path

url_pattern = rule.get("urlPattern")
assert isinstance(url_pattern, dict), path
assert isinstance(url_pattern["include"], list), path
assert Patterns(url_pattern)

assert rule.get("processor"), path
assert isinstance(rule.get("processor"), str), path

if "args" in rule:
assert isinstance(rule["args"], (list, tuple))

0 comments on commit 142ee84

Please sign in to comment.