Skip to content

Commit

Permalink
Added gh-actions for test automation (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
jay-m-dev authored Apr 14, 2023
1 parent 0b3ab12 commit 394b17b
Show file tree
Hide file tree
Showing 10 changed files with 147 additions and 2 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Tests

on:
- push
- pull_request

jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
python-version: ['3.10']

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install tox tox-gh-actions
- name: Test with tox
run: tox
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ TPOT2.egg-info
*.json
joblib/
cache_folder/
dask-worker-space/
dask-worker-space/
.tox/
*.egg-info/
.coverage
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# TPOT2 ALPHA

![Tests](https://github.com/jay-m-dev/tpot2/actions/workflows/tests.yml/badge.svg)

TPOT2 is a rewrite of TPOT with some additional functionality. Notably, we added support for graph-based pipelines and additional parameters to better specify the desired search space.
TPOT2 is currently in Alpha. This means that there will likely be some backwards incompatible changes to the API as we develop. Some implemented features may be buggy. There is a list of known issues written at the bottom of this README. Some features have placeholder names or are listed as "Experimental" in the doc string. These are features that may not be fully implemented and may or may work with all other features.

Expand Down
23 changes: 23 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
[build-system]
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"

[tool.pytest.ini_options]
addopts = "--cov=tpot2"
testpaths = [
"tpot2/tests",
]

[tool.mypy]
mypy_path = "tpot2"
check_untyped_defs = true
disallow_any_generics = true
ignore_missing_imports = true
no_implicit_optional = true
show_error_codes = true
strict_equality = true
warn_redundant_casts = true
warn_return_any = true
warn_unreachable = true
warn_unused_configs = true
no_implicit_reexport = true
5 changes: 5 additions & 0 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
flake8==6.0.0
tox==4.4.12
pytest==7.3.0
pytest-cov==4.0.0
mypy==1.2.0
13 changes: 13 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[options.extras_require]
testing =
pytest>=6.0
pytest-cov>=2.0
mypy>=0.910
flake8>=3.9
tox>=3.24

[options.package_data]
tpot2 = py.typed

[flake8]
max-line-length = 120
30 changes: 30 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[tox]
minversion = 3.28.0
# flake8 and mypy outputs severla errors, so we disable them for now
# envlist = py310, flake8, mypy
envlist = py310
isolated_build = true

[gh-actions]
python =
3.10: py310
# 3.10: py310, flake8, mypy

[testenv]
setenv =
PYTHONPATH = {toxinidir}
deps =
-r{toxinidir}/requirements_dev.txt
commands =
pytest --basetemp={envtmpdir}

[testenv:flake8]
basepython = python3.10
deps = flake8
commands = flake8 tpot2

[testenv:mypy]
basepython = python3.10
deps =
-r{toxinidir}/requirements_dev.txt
commands = mypy tpot2
14 changes: 14 additions & 0 deletions tpot2/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import pytest
import sys


@pytest.fixture
def capture_stdout(monkeypatch):
buffer = {"stdout": "", "write_calls": 0}

def fake_write(s):
buffer["stdout"] += s
buffer["write_calls"] += 1

monkeypatch.setattr(sys.stdout, "write", fake_write)
return buffer
27 changes: 27 additions & 0 deletions tpot2/tests/test_hello_world.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""
Test hello world.
Notes:
parameterizing the test_input and expected values allows tests continue running even if one fails.
xfail marks a test as expected to fail. This is useful for tests that are not yet implemented.
fixtures are used to setup and teardown tests. They are useful for tests that require a lot of setup.
We can implement fixtures if we need them.
"""

import pytest


@pytest.mark.parametrize("test_input,expected", [
("Hello World", "Hello World"),
])
def test_hello_world(test_input, expected):
assert test_input is expected


@pytest.mark.xfail(reason="Not yet implemented")
def test_divide_by_zero():
assert 1 / 0 == 1


def test_print(capture_stdout):
print("Hello World")
assert capture_stdout["stdout"] == "Hello World\n"
4 changes: 3 additions & 1 deletion tpot2/tests/test_nodes.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Test all nodes have all dictionaries
import pytest
import tpot2.GraphSklearn as GraphSklearn
import tpot2.graphsklearn as GraphSklearn


@pytest.mark.skip(reason="Not yet implemented")
def test_BaseNode_static_methods():
n1 = GraphSklearn.BaseNode()
n2 = GraphSklearn.BaseNode()
Expand Down Expand Up @@ -93,6 +94,7 @@ def test_BaseNode_static_methods():
assert this_node in other_node.node_set


@pytest.mark.skip(reason="Not yet implemented")
def test_BaseNode_static_crossover_methods():
n1 = GraphSklearn.BaseNode()
n2 = GraphSklearn.BaseNode()
Expand Down

0 comments on commit 394b17b

Please sign in to comment.