Skip to content

Commit 953c8e6

Browse files
Merge pull request #59 from benjeffery/ci
Add tests and lint to CI
2 parents d405315 + 1e59f84 commit 953c8e6

File tree

6 files changed

+102
-9
lines changed

6 files changed

+102
-9
lines changed

.flake8

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[flake8]
2+
# Based directly on Black's recommendations:
3+
# https://black.readthedocs.io/en/stable/the_black_code_style.html#line-length
4+
max-line-length = 81
5+
select = A,C,E,F,W,B,B950
6+
#B305 doesn't like `.next()` that is a key Tree method.
7+
ignore = E203, E501, W503, B305

.github/workflows/tests.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Tests
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches: [main, test]
7+
8+
jobs:
9+
pre-commit:
10+
name: Lint
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Cancel Previous Runs
14+
uses: styfle/[email protected]
15+
with:
16+
access_token: ${{ github.token }}
17+
- uses: actions/checkout@v3
18+
- uses: actions/setup-python@v4
19+
with:
20+
python-version: '3.11'
21+
- uses: pre-commit/[email protected]
22+
23+
test:
24+
name: Python
25+
runs-on: ${{ matrix.os }}
26+
strategy:
27+
fail-fast: false
28+
matrix:
29+
python: [ "3.11" ]
30+
os: [ ubuntu-latest, ]
31+
defaults:
32+
run:
33+
shell: bash
34+
steps:
35+
- name: Cancel Previous Runs
36+
uses: styfle/[email protected]
37+
with:
38+
access_token: ${{ github.token }}
39+
40+
- name: Checkout
41+
uses: actions/checkout@v3
42+
43+
- uses: actions/setup-python@v4
44+
with:
45+
python-version: '3.11'
46+
cache: 'pip'
47+
- run: pip install -r requirements.txt
48+
- run: python -m pytest tests

.pre-commit-config.yaml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v4.4.0
4+
hooks:
5+
- id: check-merge-conflict
6+
- id: debug-statements
7+
- id: mixed-line-ending
8+
- id: check-case-conflict
9+
- id: check-yaml
10+
- repo: https://github.com/asottile/reorder_python_imports
11+
rev: v3.10.0
12+
hooks:
13+
- id: reorder-python-imports
14+
args: [ --unclassifiable-application-module=_tsinfer ]
15+
- repo: https://github.com/asottile/pyupgrade
16+
rev: v3.10.1
17+
hooks:
18+
- id: pyupgrade
19+
args: [ --py3-plus, --py310-plus ]
20+
- repo: https://github.com/psf/black
21+
rev: 23.7.0
22+
hooks:
23+
- id: black
24+
language_version: python3
25+
- repo: https://github.com/asottile/blacken-docs
26+
rev: 1.16.0
27+
hooks:
28+
- id: blacken-docs
29+
args: [--skip-errors]
30+
additional_dependencies: [black==22.3.0]
31+
language_version: python3
32+
- repo: https://github.com/pycqa/flake8
33+
rev: 6.1.0
34+
hooks:
35+
- id: flake8
36+
args: [--config=.flake8]
37+
additional_dependencies: ["flake8-bugbear==23.7.10", "flake8-builtins==2.1.0"]

model.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import tskit
44
import numpy as np
5-
import utils
65
import numba
76
import pandas as pd
87
import numba
@@ -156,11 +155,13 @@ def compute_per_tree_stats(ts):
156155
ts.edges_child,
157156
)
158157

158+
159159
class TSModel:
160160
"""
161161
A wrapper around a tskit.TreeSequence object that provides some
162162
convenience methods for analysing the tree sequence.
163163
"""
164+
164165
def __init__(self, ts, name=None):
165166
self.ts = ts
166167
self.name = name

requirements.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ hvplot
33
xarray
44
datashader
55
tskit
6-
seaborn
6+
seaborn
7+
pre-commit
8+
pytest

tests/test_data_model.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
import pytest
2-
import tskit
3-
import numpy.testing as nt
41
import numpy as np
5-
62
import model
7-
import utils
3+
import numpy.testing as nt
4+
import tskit
5+
86

97

108
def single_tree_example_ts():
@@ -42,6 +40,7 @@ def single_tree_recurrent_mutation_example_ts():
4240
ts = tables.tree_sequence()
4341
return tables.tree_sequence()
4442

43+
4544
def multiple_trees_example_ts():
4645
# 2.00┊ 4 ┊ 4 ┊
4746
# ┊ ┏━┻┓ ┊ ┏┻━┓ ┊
@@ -162,8 +161,7 @@ def test_single_tree_example(self):
162161
assert len(df) == 7
163162
nt.assert_array_equal(df.time, [0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 2.0])
164163
nt.assert_array_equal(df.num_mutations, [1, 1, 1, 1, 1, 1, 0])
165-
nt.assert_array_equal(df.ancestors_span, [
166-
10, 10, 10, 10, 10, 10, -np.inf])
164+
nt.assert_array_equal(df.ancestors_span, [10, 10, 10, 10, 10, 10, -np.inf])
167165

168166
def test_multiple_tree_example(self):
169167
ts = multiple_trees_example_ts()

0 commit comments

Comments
 (0)