Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .deepsource.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ version = 1

test_patterns = [
"tests/**",
"test_*.py"
"test_*.py",
"tests_integ/**",
]

[[analyzers]]
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
run: make mypy

- name: Run Tests
run: make test
run: make test-integ

- name: Upload Coverage
uses: codecov/codecov-action@v3
Expand Down
22 changes: 22 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,28 @@ jobs:
- name: Build
run: poetry build

integ:
needs:
- test
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v3

- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: 3.8

- name: Install Poetry
run: pip install poetry==1.7

- name: Install Dependencies
run: poetry install --with=dev

- name: Run Integration Tests
run: make test-integ

codecov:
needs:
- lint
Expand Down
5 changes: 5 additions & 0 deletions .pytest-tests.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[pytest]
addopts = --cov json_logic_asp/ --cov-report html --cov-report xml --cov-report term
testpaths =
tests
log_level = DEBUG
4 changes: 4 additions & 0 deletions .pytest-tests_integ.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[pytest]
testpaths =
tests_integ
log_level = INFO
17 changes: 10 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
.PHONY: target format lint test pr build
.PHONY: target format lint test test-integ pr build

target:
@$(MAKE) pr

format:
poetry run ruff format json_logic_asp/ tests/
poetry run ruff format json_logic_asp/ tests/ tests_integ/

lint: format
poetry run ruff check --fix json_logic_asp/ tests/
poetry run ruff check --fix json_logic_asp/ tests/ tests_integ/

lint-strict: format
poetry run ruff check json_logic_asp/ tests/
poetry run ruff check json_logic_asp/ tests/ tests_integ/

mypy:
poetry run mypy --pretty --check-untyped-def json_logic_asp/ tests/
poetry run mypy --pretty --check-untyped-def json_logic_asp/ tests/ tests_integ/

test:
poetry run pytest
poetry run pytest -c .pytest-tests.ini

pr: lint mypy test
test-integ: test
poetry run pytest -c .pytest-tests_integ.ini -v

pr: lint mypy test-integ

build: pr
poetry build
7 changes: 0 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,6 @@ requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"


[tool.pytest.ini_options]
addopts = "--cov json_logic_asp/ --cov-report html --cov-report xml --cov-report term"
testpaths = [
"tests",
]
log_level = "DEBUG"

[tool.ruff]
line-length = 120

Expand Down
Empty file added tests_integ/__init__.py
Empty file.
7 changes: 7 additions & 0 deletions tests_integ/test_data_translations/simple.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"a": "b",
"c": 3,
"d": {
"e": 48
}
}
6 changes: 6 additions & 0 deletions tests_integ/test_data_translations/simple.lp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
% a : b
var(s0cc175b9c0f1b6a831c399e269772661, s92eb5ffee6ae2fec3ad71c777531578f).
% c : 3
var(s4a8a08f09d37b73795649038408b5f33, 3).
% d.e : 48
var(s405f7563a1a79cad802baab832d146dd, 48).
Empty file added tests_integ/test_evaluation.py
Empty file.
6 changes: 6 additions & 0 deletions tests_integ/test_rule_translations/simple.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"==": [
{"var": "a"},
"b"
]
}
4 changes: 4 additions & 0 deletions tests_integ/test_rule_translations/simple.lp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
% a EQ b
eq(mock2) :- var(s0cc175b9c0f1b6a831c399e269772661, V1), V1 == s92eb5ffee6ae2fec3ad71c777531578f.
% simple
rule(s8dbdda48fb8748d6746f1965824e966a) :- eq(mock2).
66 changes: 66 additions & 0 deletions tests_integ/test_translation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import json
from os import listdir
from os.path import isfile, join
from pathlib import Path

import pytest

from json_logic_asp.models.translator_dto import DataInput, RuleInput
from json_logic_asp.translator import generate_single_data_asp_definition, generate_single_rule_asp_definition
from tests.fixtures import cuid_fixture # noqa

TESTS_RULES_FOLDER = Path(__file__).parent / "test_rule_translations"
TESTS_RULES_FILE_NAMES = list(
set([f.split(".")[0] for f in listdir(TESTS_RULES_FOLDER) if isfile(join(TESTS_RULES_FOLDER, f))])
)

TESTS_DATAS_FOLDER = Path(__file__).parent / "test_data_translations"
TESTS_DATAS_FILE_NAMES = list(
set([f.split(".")[0] for f in listdir(TESTS_DATAS_FOLDER) if isfile(join(TESTS_DATAS_FOLDER, f))])
)


@pytest.mark.parametrize(
"file_name",
TESTS_RULES_FILE_NAMES,
ids=TESTS_RULES_FILE_NAMES,
)
def test_rule_translation(file_name):
with open(TESTS_RULES_FOLDER / f"{file_name}.json") as f:
jl_rule = json.loads(f.read())

with open(TESTS_RULES_FOLDER / f"{file_name}.lp") as f:
expected_asp_rule = f.read()

asp_rule = generate_single_rule_asp_definition(
rule_input=RuleInput(
rule_id=file_name,
rule_tree=jl_rule,
),
with_comments=True,
)

assert asp_rule.strip() == expected_asp_rule.strip()


@pytest.mark.parametrize(
"file_name",
TESTS_DATAS_FILE_NAMES,
ids=TESTS_DATAS_FILE_NAMES,
)
def test_data_translation(file_name):
with open(TESTS_DATAS_FOLDER / f"{file_name}.json") as f:
data_object = json.loads(f.read())

with open(TESTS_DATAS_FOLDER / f"{file_name}.lp") as f:
expected_asp_data = f.read()

asp_data = generate_single_data_asp_definition(
data_input=DataInput(
data_id=file_name,
data_object=data_object,
),
with_comments=True,
)

assert asp_data.strip() == expected_asp_data.strip()