Skip to content

Commit

Permalink
Loosen dependency restriction (#7)
Browse files Browse the repository at this point in the history
* Loosen dependency

* Move to new release scheme

* Change caching in CI

* Save data cache after running tests

* Don't use download tests in CI
  • Loading branch information
dobraczka authored Mar 28, 2023
1 parent 131094f commit b2abe85
Show file tree
Hide file tree
Showing 9 changed files with 950 additions and 818 deletions.
14 changes: 3 additions & 11 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@ on:


jobs:
build:

not_slow:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
python-version: [3.8, "3.10"]
python-version: [3.8, "3.11"]
os: [ubuntu-latest, macos-latest, windows-latest]

steps:
Expand All @@ -33,12 +32,5 @@ jobs:
- name: Install dependencies
run: |
python -m pip install nox_poetry
- name: Cache dataset downloads
uses: actions/cache@v3
with:
# datasets are stored in `~/.data/ea-dataset-provider/`
path: ~/.data/ea-dataset-provider/
key: alwaysthesame
- name: Test with nox
run: nox -s tests

run: nox -s tests -- -m "not slow"
61 changes: 0 additions & 61 deletions .github/workflows/publish.yml

This file was deleted.

16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [0.1.1] - 2023-03-27

### Fixed

- Loosen python dependency

[0.1.1]: https://github.com/dobraczka/sylloge/releases/tag/v1.0.0
1 change: 1 addition & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
def tests(session: Session) -> None:
args = session.posargs or ["--cov", "--cov-report=xml"]
session.install(".[all]")
session.install("strawman")
session.install("pytest")
session.install("pytest-cov")
session.install("pytest-mock")
Expand Down
1,562 changes: 817 additions & 745 deletions poetry.lock

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ repository = "https://github.com/dobraczka/sylloge"
"Documentation" = "https://sylloge.readthedocs.io"

[tool.poetry.dependencies]
python = ">=3.8,<3.11"
python = ">=3.8,<4.0"
Sphinx = {version = "^5.0.0", optional = true}
insegel = {version = "^1.3.1", optional = true}
pystow = "^0.4.6"
Expand Down Expand Up @@ -46,6 +46,9 @@ darglint = "^1.8.1"
[tool.poetry.extras]
docs = ["sphinx", "insegel", "sphinx-automodapi", "sphinx-autodoc-typehints"]

[tool.poetry.group.dev.dependencies]
strawman = "^0.1.2"

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
Expand Down Expand Up @@ -85,3 +88,7 @@ line_length = 88
include_trailing_comma = true
reverse_relative = true

[tool.pytest.ini_options]
markers = [
"slow: mark test as slow"
]
57 changes: 57 additions & 0 deletions tests/mocks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
from pathlib import Path
from typing import Iterable, Union

import pandas as pd
from strawman import dummy_df, dummy_triples
from util import DatasetStatistics

from sylloge.base import EA_SIDE_LEFT, EA_SIDE_RIGHT, EA_SIDES


class DataPathMocker:
def __init__(self, data_path):
self.data_path = data_path

def mock_data_path(self):
return self.data_path


class ResourceMocker:
def __init__(self, statistic: DatasetStatistics, fraction: float):
self.statistic = statistic
self.fraction = fraction

def mock_read(self, path: str, names: Iterable):
return self.mock_read_zipfile_csv(path="", inner_path=path)

def mock_read_zipfile_csv(
self, path: Union[str, Path], inner_path: str, sep: str = "\t", **kwargs
) -> pd.DataFrame:
if "rel_triples_1" in inner_path:
return dummy_triples(
int(self.statistic.num_rel_triples_left * self.fraction),
entity_prefix=EA_SIDE_LEFT,
)
elif "rel_triples_2" in inner_path:
return dummy_triples(
int(self.statistic.num_rel_triples_right * self.fraction),
entity_prefix=EA_SIDE_RIGHT,
)
elif "attr_triples_1" in inner_path:
return dummy_triples(
int(self.statistic.num_attr_triples_left * self.fraction),
entity_prefix=EA_SIDE_LEFT,
relation_triples=False,
)
elif "attr_triples_2" in inner_path:
return dummy_triples(
int(self.statistic.num_attr_triples_right * self.fraction),
entity_prefix=EA_SIDE_RIGHT,
relation_triples=False,
)
elif "_links" in inner_path:
return dummy_df(
shape=(int(self.statistic.num_ent_links * self.fraction), 2),
content_length=100,
columns=list(EA_SIDES),
)
25 changes: 25 additions & 0 deletions tests/test_moviebenchmark.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Dict

import pytest
from mocks import DataPathMocker, ResourceMocker
from util import DatasetStatistics

from sylloge import MovieGraphBenchmark
Expand Down Expand Up @@ -40,6 +41,7 @@
]


@pytest.mark.slow
@pytest.mark.parametrize("params,statistic", statistics_with_params)
def test_movie_benchmark(params: Dict, statistic: DatasetStatistics):
ds = MovieGraphBenchmark(**params)
Expand All @@ -64,3 +66,26 @@ def test_movie_benchmark(params: Dict, statistic: DatasetStatistics):
assert len(fold.train) == 496 or len(fold.train) == 497
assert len(fold.test) == 1738
assert len(fold.val) == 249 or len(fold.val) == 248


@pytest.mark.parametrize("params,statistic", statistics_with_params)
def test_movie_benchmark_mock(
params: Dict, statistic: DatasetStatistics, mocker, tmpdir
):
rm = ResourceMocker(statistic=statistic, fraction=0.1)
dp_mocker = DataPathMocker(data_path=tmpdir)
mocker.patch("moviegraphbenchmark.loading._read", rm.mock_read)
mocker.patch(
"moviegraphbenchmark.create_graph._data_path", dp_mocker.mock_data_path
)
ds = MovieGraphBenchmark(**params)
assert ds.rel_triples_left is not None
assert ds.rel_triples_right is not None
assert ds.attr_triples_left is not None
assert ds.attr_triples_right is not None
assert ds.ent_links is not None
assert ds.folds is not None
for fold in ds.folds:
assert fold.train is not None
assert fold.test is not None
assert fold.val is not None
23 changes: 23 additions & 0 deletions tests/test_open_ea.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Dict

import pytest
from mocks import ResourceMocker
from util import DatasetStatistics

from sylloge import OpenEA
Expand Down Expand Up @@ -170,6 +171,7 @@
]


@pytest.mark.slow
@pytest.mark.parametrize("params,statistic", statistics_with_params)
def test_open_ea(params: Dict, statistic: DatasetStatistics):
ds = OpenEA(**params)
Expand All @@ -179,6 +181,7 @@ def test_open_ea(params: Dict, statistic: DatasetStatistics):
assert len(ds.attr_triples_right) == statistic.num_attr_triples_right
assert len(ds.ent_links) == statistic.num_ent_links
assert ds.folds is not None
assert len(ds.folds) == 5
for fold in ds.folds:
if params["size"] == SIZE_15K:
assert len(fold.train) == 3000
Expand All @@ -188,3 +191,23 @@ def test_open_ea(params: Dict, statistic: DatasetStatistics):
assert len(fold.train) == 20000
assert len(fold.test) == 70000
assert len(fold.val) == 10000


@pytest.mark.parametrize("params,statistic", statistics_with_params)
def test_open_ea_mock(params: Dict, statistic: DatasetStatistics, mocker):
left_name, right_name = params["graph_pair"].split("_")
fraction = 0.01 if params["size"] == SIZE_15K else 0.001
rm = ResourceMocker(statistic=statistic, fraction=fraction)
mocker.patch("sylloge.base.read_zipfile_csv", rm.mock_read_zipfile_csv)
ds = OpenEA(**params)
assert ds.rel_triples_left is not None
assert ds.rel_triples_right is not None
assert ds.attr_triples_left is not None
assert ds.attr_triples_right is not None
assert ds.ent_links is not None
assert ds.folds is not None
assert len(ds.folds) == 5
for fold in ds.folds:
assert fold.train is not None
assert fold.test is not None
assert fold.val is not None

0 comments on commit b2abe85

Please sign in to comment.