Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update CI and support pytest 8 #5

Merged
merged 9 commits into from
Oct 24, 2024
Merged
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
Original file line number Diff line number Diff line change
@@ -1,31 +1,36 @@
name: Python Package
on: [push, pull_request]
name: Python Test
on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
build-linux:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ['3.7', '3.8', '3.9', '3.10']

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e .[dev]
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Test with pytest
- name: Test with tox
run: |
cd tests
pytest .
tox run
env:
TOX_GH_MAJOR_MINOR: ${{ matrix.python-version }}
- name: Test parallel execution
run: |
cd integration-tests/parallelization
bash time-parallel-tests.sh .
- name: Publish Unit Test Results
uses: EnricoMi/publish-unit-test-result-action@v2.0.0-beta.2
uses: EnricoMi/publish-unit-test-result-action@v2
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2022 Inline Tests Dev Team
Copyright (c) 2022-present Inline Tests Dev Team

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
51 changes: 26 additions & 25 deletions demo/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,34 @@
import re
from inline import itest


def get_assignment_map_from_checkpoint(tvars, init_checkpoint):
"""Compute the union of the current variables and checkpoint variables."""
assignment_map = {}
initialized_variable_names = {}
"""Compute the union of the current variables and checkpoint variables."""
assignment_map = {}
initialized_variable_names = {}

name_to_variable = collections.OrderedDict()
for var in tvars:
name = var.name
# statement under test
m = re.match("^(.*):\\d+$", name)
# inline test
itest().given(name, "a:0").check_eq(m.group(1), "a")
# a failing inline test
# itest().given(name, "a:0").check_eq(m.group(1), "aaa")
if m is not None:
name = m.group(1)
name_to_variable[name] = var
name_to_variable = collections.OrderedDict()
for var in tvars:
name = var.name
# statement under test
m = re.match("^(.*):\\d+$", name)
# inline test
itest().given(name, "a:0").check_eq(m.group(1), "a")
# a failing inline test
# itest().given(name, "a:0").check_eq(m.group(1), "aaa")
if m is not None:
name = m.group(1)
name_to_variable[name] = var

init_vars = tf.train.list_variables(init_checkpoint)
init_vars = tf.train.list_variables(init_checkpoint)

assignment_map = collections.OrderedDict()
for x in init_vars:
(name, var) = (x[0], x[1])
if name not in name_to_variable:
continue
assignment_map[name] = name
initialized_variable_names[name] = 1
initialized_variable_names[name + ":0"] = 1
assignment_map = collections.OrderedDict()
for x in init_vars:
(name, var) = (x[0], x[1])
if name not in name_to_variable:
continue
assignment_map[name] = name
initialized_variable_names[name] = 1
initialized_variable_names[name + ":0"] = 1

return (assignment_map, initialized_variable_names)
return (assignment_map, initialized_variable_names)
9 changes: 9 additions & 0 deletions demo/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,45 @@

### display name: customize test name, default name is filename+line number


def inline_test_with_name(a):
b = a + 1
itest(test_name="test-with-name").given(a, 1).check_eq(b, 2)


### parameterized tests: pass different sets of inputs to tests


def inline_test_parameterized(a):
b = a + 1
itest(parameterized=True).given(a, [1, 2, 3]).check_eq(b, [2, 3, 4])


### repeated tests: repeat a test a specified number of times


def inline_test_repeated(a):
b = a + 1
itest(repeated=3).given(a, 1).check_eq(b, 2)


### disabled tests: disable a test


def inline_test_disabled(a):
b = a + 1
itest(disabled=True).given(a, 1).check_eq(b, "this test is disabled")


### timeout: fail a test if the execution time exceeds a given duration


def slow_method():
time.sleep(0.01)
# time.sleep(0.1)
return 1


def inline_test_with_timeout(a):
b = a + 1
# this inline test will fail if you increase the sleep time in slow_method
Expand All @@ -44,13 +50,15 @@ def inline_test_with_timeout(a):

### assumptions: execute test when the assumption is satisfied


def inline_test_with_assume(a):
b = a + 1
itest().assume(False).given(a, 1).check_eq(b, 2)


### more assertions


def inline_test_assertions(a):
b = a + 1
itest().given(a, 1).check_neq(b, 1)
Expand All @@ -67,6 +75,7 @@ def inline_test_assertions(a):
### tagged tests: tag tests for filtering
### run tests in order: Run some tests first


def inline_test_with_tags(a):
b = a + 1
itest(test_name="foo1", tag=["foo"]).given(a, 1).check_eq(b, 2)
Expand Down
12 changes: 6 additions & 6 deletions demo/parallel/a.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

a = 0
a = a + 1
itest("1", tag = ["add"]).given(a, 1).check_eq(a, 2)
itest("1", tag = ["add"]).given(a, 1).check_eq(a, 2)
itest("1", tag = ["add"]).given(a, 1).check_eq(a, 2)
itest("1", tag=["add"]).given(a, 1).check_eq(a, 2)
itest("1", tag=["add"]).given(a, 1).check_eq(a, 2)
itest("1", tag=["add"]).given(a, 1).check_eq(a, 2)
a = a + 2
itest("2").given(a, 1).check_eq(a, 3)
itest("2").given(a, 1).check_eq(a, 3)
itest("2").given(a, 1).check_eq(a, 3)
a = a - 1
itest("3", tag = ["minus"]).given(a, 1).check_eq(a, 0)
itest("3", tag = ["minus"]).given(a, 1).check_eq(a, 0)
itest("3", tag = ["minus"]).given(a, 1).check_eq(a, 0)
itest("3", tag=["minus"]).given(a, 1).check_eq(a, 0)
itest("3", tag=["minus"]).given(a, 1).check_eq(a, 0)
itest("3", tag=["minus"]).given(a, 1).check_eq(a, 0)
12 changes: 6 additions & 6 deletions demo/parallel/b.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
sleep = 0.1
b = 0
b = b + 1
itest("1", tag = ["add"]).given(b, 1).check_eq(b, 2).check_eq(time.sleep(sleep), None)
itest("1", tag = ["add"]).given(b, 1).check_eq(b, 2)
itest("1", tag = ["add"]).given(b, 1).check_eq(b, 2)
itest("1", tag=["add"]).given(b, 1).check_eq(b, 2).check_eq(time.sleep(sleep), None)
itest("1", tag=["add"]).given(b, 1).check_eq(b, 2)
itest("1", tag=["add"]).given(b, 1).check_eq(b, 2)
b = b + 2
itest("2").given(b, 1).check_eq(b, 3).check_eq(time.sleep(sleep), None)
itest("2").given(b, 1).check_eq(b, 3)
itest("2").given(b, 1).check_eq(b, 3)
b = b - 1
itest("3", tag = ["minus"]).given(b, 1).check_eq(b, 0).check_eq(time.sleep(sleep), None)
itest("3", tag = ["minus"]).given(b, 1).check_eq(b, 0)
itest("3", tag = ["minus"]).given(b, 1).check_eq(b, 0)
itest("3", tag=["minus"]).given(b, 1).check_eq(b, 0).check_eq(time.sleep(sleep), None)
itest("3", tag=["minus"]).given(b, 1).check_eq(b, 0)
itest("3", tag=["minus"]).given(b, 1).check_eq(b, 0)
12 changes: 6 additions & 6 deletions demo/parallel/c.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
sleep = 0.2
c = 0
c = c + 1
itest("1", tag = ["add"]).given(c, 1).check_eq(c, 2).check_eq(time.sleep(sleep), None)
itest("1", tag = ["add"]).given(c, 1).check_eq(c, 2)
itest("1", tag = ["add"]).given(c, 1).check_eq(c, 2)
itest("1", tag=["add"]).given(c, 1).check_eq(c, 2).check_eq(time.sleep(sleep), None)
itest("1", tag=["add"]).given(c, 1).check_eq(c, 2)
itest("1", tag=["add"]).given(c, 1).check_eq(c, 2)
c = c + 2
itest("2").given(c, 1).check_eq(c, 3).check_eq(time.sleep(sleep), None)
itest("2").given(c, 1).check_eq(c, 3)
itest("2").given(c, 1).check_eq(c, 3)
c = c - 1
itest("3", tag = ["minus"]).given(c, 1).check_eq(c, 0).check_eq(time.sleep(sleep), None)
itest("3", tag = ["minus"]).given(c, 1)
itest("3", tag = ["minus"]).given(c, 1)
itest("3", tag=["minus"]).given(c, 1).check_eq(c, 0).check_eq(time.sleep(sleep), None)
itest("3", tag=["minus"]).given(c, 1)
itest("3", tag=["minus"]).given(c, 1)
12 changes: 6 additions & 6 deletions demo/parallel/d.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
sleep = 0.1
d = 0
d = d + 1
itest("1", tag = ["add"]).given(d, 1).check_eq(d, 2).check_eq(time.sleep(sleep), None)
itest("1", tag = ["add"]).given(d, 1).check_eq(d, 2)
itest("1", tag = ["add"]).given(d, 1).check_eq(d, 2)
itest("1", tag=["add"]).given(d, 1).check_eq(d, 2).check_eq(time.sleep(sleep), None)
itest("1", tag=["add"]).given(d, 1).check_eq(d, 2)
itest("1", tag=["add"]).given(d, 1).check_eq(d, 2)
d = d + 2
itest("2").given(d, 1).check_eq(d, 3).check_eq(time.sleep(sleep), None)
itest("2").given(d, 1).check_eq(d, 3)
itest("2").given(d, 1).check_eq(d, 3)
d = d - 1
itest("3", tag = ["minus"]).given(d, 1).check_eq(d, 0).check_eq(time.sleep(sleep), None)
itest("3", tag = ["minus"]).given(d, 1).check_eq(d, 0)
itest("3", tag = ["minus"]).given(d, 1).check_eq(d, 0)
itest("3", tag=["minus"]).given(d, 1).check_eq(d, 0).check_eq(time.sleep(sleep), None)
itest("3", tag=["minus"]).given(d, 1).check_eq(d, 0)
itest("3", tag=["minus"]).given(d, 1).check_eq(d, 0)
12 changes: 6 additions & 6 deletions integration-tests/parallelization/test_files/a.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

a = 0
a = a + 1
itest("1", tag = ["add"]).given(a, 1).check_eq(a, 2)
itest("1", tag = ["add"]).given(a, 1).check_eq(a, 2)
itest("1", tag = ["add"]).given(a, 1).check_eq(a, 2)
itest("1", tag=["add"]).given(a, 1).check_eq(a, 2)
itest("1", tag=["add"]).given(a, 1).check_eq(a, 2)
itest("1", tag=["add"]).given(a, 1).check_eq(a, 2)
a = a + 2
itest("2").given(a, 1).check_eq(a, 3)
itest("2").given(a, 1).check_eq(a, 3)
itest("2").given(a, 1).check_eq(a, 3)
a = a - 1
itest("3", tag = ["minus"]).given(a, 1).check_eq(a, 0)
itest("3", tag = ["minus"]).given(a, 1).check_eq(a, 0)
itest("3", tag = ["minus"]).given(a, 1).check_eq(a, 0)
itest("3", tag=["minus"]).given(a, 1).check_eq(a, 0)
itest("3", tag=["minus"]).given(a, 1).check_eq(a, 0)
itest("3", tag=["minus"]).given(a, 1).check_eq(a, 0)
12 changes: 6 additions & 6 deletions integration-tests/parallelization/test_files/b.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
sleep = 1
b = 0
b = b + 1
itest("1", tag = ["add"]).given(b, 1).check_eq(b, 2).check_eq(time.sleep(sleep), None)
itest("1", tag = ["add"]).given(b, 1).check_eq(b, 2)
itest("1", tag = ["add"]).given(b, 1).check_eq(b, 2)
itest("1", tag=["add"]).given(b, 1).check_eq(b, 2).check_eq(time.sleep(sleep), None)
itest("1", tag=["add"]).given(b, 1).check_eq(b, 2)
itest("1", tag=["add"]).given(b, 1).check_eq(b, 2)
b = b + 2
itest("2").given(b, 1).check_eq(b, 3).check_eq(time.sleep(sleep), None)
itest("2").given(b, 1).check_eq(b, 3)
itest("2").given(b, 1).check_eq(b, 3)
b = b - 1
itest("3", tag = ["minus"]).given(b, 1).check_eq(b, 0).check_eq(time.sleep(sleep), None)
itest("3", tag = ["minus"]).given(b, 1).check_eq(b, 0)
itest("3", tag = ["minus"]).given(b, 1).check_eq(b, 0)
itest("3", tag=["minus"]).given(b, 1).check_eq(b, 0).check_eq(time.sleep(sleep), None)
itest("3", tag=["minus"]).given(b, 1).check_eq(b, 0)
itest("3", tag=["minus"]).given(b, 1).check_eq(b, 0)
12 changes: 6 additions & 6 deletions integration-tests/parallelization/test_files/c.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
sleep = 2
c = 0
c = c + 1
itest("1", tag = ["add"]).given(c, 1).check_eq(c, 2).check_eq(time.sleep(sleep), None)
itest("1", tag = ["add"]).given(c, 1).check_eq(c, 2)
itest("1", tag = ["add"]).given(c, 1).check_eq(c, 2)
itest("1", tag=["add"]).given(c, 1).check_eq(c, 2).check_eq(time.sleep(sleep), None)
itest("1", tag=["add"]).given(c, 1).check_eq(c, 2)
itest("1", tag=["add"]).given(c, 1).check_eq(c, 2)
c = c + 2
itest("2").given(c, 1).check_eq(c, 3).check_eq(time.sleep(sleep), None)
itest("2").given(c, 1).check_eq(c, 3)
itest("2").given(c, 1).check_eq(c, 3)
c = c - 1
itest("3", tag = ["minus"]).given(c, 1).check_eq(c, 0).check_eq(time.sleep(sleep), None)
itest("3", tag = ["minus"]).given(c, 1)
itest("3", tag = ["minus"]).given(c, 1)
itest("3", tag=["minus"]).given(c, 1).check_eq(c, 0).check_eq(time.sleep(sleep), None)
itest("3", tag=["minus"]).given(c, 1)
itest("3", tag=["minus"]).given(c, 1)
12 changes: 6 additions & 6 deletions integration-tests/parallelization/test_files/d.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
sleep = 1
d = 0
d = d + 1
itest("1", tag = ["add"]).given(d, 1).check_eq(d, 2).check_eq(time.sleep(sleep), None)
itest("1", tag = ["add"]).given(d, 1).check_eq(d, 2)
itest("1", tag = ["add"]).given(d, 1).check_eq(d, 2)
itest("1", tag=["add"]).given(d, 1).check_eq(d, 2).check_eq(time.sleep(sleep), None)
itest("1", tag=["add"]).given(d, 1).check_eq(d, 2)
itest("1", tag=["add"]).given(d, 1).check_eq(d, 2)
d = d + 2
itest("2").given(d, 1).check_eq(d, 3).check_eq(time.sleep(sleep), None)
itest("2").given(d, 1).check_eq(d, 3)
itest("2").given(d, 1).check_eq(d, 3)
d = d - 1
itest("3", tag = ["minus"]).given(d, 1).check_eq(d, 0).check_eq(time.sleep(sleep), None)
itest("3", tag = ["minus"]).given(d, 1).check_eq(d, 0)
itest("3", tag = ["minus"]).given(d, 1).check_eq(d, 0)
itest("3", tag=["minus"]).given(d, 1).check_eq(d, 0).check_eq(time.sleep(sleep), None)
itest("3", tag=["minus"]).given(d, 1).check_eq(d, 0)
itest("3", tag=["minus"]).given(d, 1).check_eq(d, 0)
12 changes: 6 additions & 6 deletions integration-tests/parallelization/test_files/e.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
sleep = 2
e = 0
e = e + 1
itest("1", tag = ["add"]).given(e, 1).check_eq(e, 2).check_eq(time.sleep(sleep), None)
itest("1", tag = ["add"]).given(e, 1).check_eq(e, 2)
itest("1", tag = ["add"]).given(e, 1).check_eq(e, 2)
itest("1", tag=["add"]).given(e, 1).check_eq(e, 2).check_eq(time.sleep(sleep), None)
itest("1", tag=["add"]).given(e, 1).check_eq(e, 2)
itest("1", tag=["add"]).given(e, 1).check_eq(e, 2)
e = e + 2
itest("2").given(e, 1).check_eq(e, 3).check_eq(time.sleep(sleep), None)
itest("2").given(e, 1).check_eq(e, 3)
itest("2").given(e, 1).check_eq(e, 3)
e = e - 1
itest("3", tag = ["minus"]).given(e, 1).check_eq(e, 0).check_eq(time.sleep(sleep), None)
itest("3", tag = ["minus"]).given(e, 1).check_eq(e, 0)
itest("3", tag = ["minus"]).given(e, 1).check_eq(e, 0)
itest("3", tag=["minus"]).given(e, 1).check_eq(e, 0).check_eq(time.sleep(sleep), None)
itest("3", tag=["minus"]).given(e, 1).check_eq(e, 0)
itest("3", tag=["minus"]).given(e, 1).check_eq(e, 0)
12 changes: 6 additions & 6 deletions integration-tests/parallelization/test_files/f.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
sleep = 1
f = 0
f = f + 1
itest("1", tag = ["add"]).given(f, 1).check_eq(f, 2).check_eq(time.sleep(sleep), None)
itest("1", tag = ["add"]).given(f, 1).check_eq(f, 2)
itest("1", tag = ["add"]).given(f, 1).check_eq(f, 2)
itest("1", tag=["add"]).given(f, 1).check_eq(f, 2).check_eq(time.sleep(sleep), None)
itest("1", tag=["add"]).given(f, 1).check_eq(f, 2)
itest("1", tag=["add"]).given(f, 1).check_eq(f, 2)
f = f + 2
itest("2").given(f, 1).check_eq(f, 3).check_eq(time.sleep(sleep), None)
itest("2").given(f, 1).check_eq(f, 3)
itest("2").given(f, 1).check_eq(f, 3)
f = f - 1
itest("3", tag = ["minus"]).given(f, 1).check_eq(f, 0).check_eq(time.sleep(sleep), None)
itest("3", tag = ["minus"]).given(f, 1).check_eq(f, 0)
itest("3", tag = ["minus"]).given(f, 1).check_eq(f, 0)
itest("3", tag=["minus"]).given(f, 1).check_eq(f, 0).check_eq(time.sleep(sleep), None)
itest("3", tag=["minus"]).given(f, 1).check_eq(f, 0)
itest("3", tag=["minus"]).given(f, 1).check_eq(f, 0)
Loading
Loading