Skip to content

Commit

Permalink
Merge pull request #59 from benjeffery/ci
Browse files Browse the repository at this point in the history
Add tests and lint to CI
  • Loading branch information
jeromekelleher authored Aug 21, 2023
2 parents d405315 + 1e59f84 commit 953c8e6
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 9 deletions.
7 changes: 7 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[flake8]
# Based directly on Black's recommendations:
# https://black.readthedocs.io/en/stable/the_black_code_style.html#line-length
max-line-length = 81
select = A,C,E,F,W,B,B950
#B305 doesn't like `.next()` that is a key Tree method.
ignore = E203, E501, W503, B305
48 changes: 48 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Tests

on:
pull_request:
push:
branches: [main, test]

jobs:
pre-commit:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Cancel Previous Runs
uses: styfle/[email protected]
with:
access_token: ${{ github.token }}
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.11'
- uses: pre-commit/[email protected]

test:
name: Python
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
python: [ "3.11" ]
os: [ ubuntu-latest, ]
defaults:
run:
shell: bash
steps:
- name: Cancel Previous Runs
uses: styfle/[email protected]
with:
access_token: ${{ github.token }}

- name: Checkout
uses: actions/checkout@v3

- uses: actions/setup-python@v4
with:
python-version: '3.11'
cache: 'pip'
- run: pip install -r requirements.txt
- run: python -m pytest tests
37 changes: 37 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-merge-conflict
- id: debug-statements
- id: mixed-line-ending
- id: check-case-conflict
- id: check-yaml
- repo: https://github.com/asottile/reorder_python_imports
rev: v3.10.0
hooks:
- id: reorder-python-imports
args: [ --unclassifiable-application-module=_tsinfer ]
- repo: https://github.com/asottile/pyupgrade
rev: v3.10.1
hooks:
- id: pyupgrade
args: [ --py3-plus, --py310-plus ]
- repo: https://github.com/psf/black
rev: 23.7.0
hooks:
- id: black
language_version: python3
- repo: https://github.com/asottile/blacken-docs
rev: 1.16.0
hooks:
- id: blacken-docs
args: [--skip-errors]
additional_dependencies: [black==22.3.0]
language_version: python3
- repo: https://github.com/pycqa/flake8
rev: 6.1.0
hooks:
- id: flake8
args: [--config=.flake8]
additional_dependencies: ["flake8-bugbear==23.7.10", "flake8-builtins==2.1.0"]
3 changes: 2 additions & 1 deletion model.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import tskit
import numpy as np
import utils
import numba
import pandas as pd
import numba
Expand Down Expand Up @@ -156,11 +155,13 @@ def compute_per_tree_stats(ts):
ts.edges_child,
)


class TSModel:
"""
A wrapper around a tskit.TreeSequence object that provides some
convenience methods for analysing the tree sequence.
"""

def __init__(self, ts, name=None):
self.ts = ts
self.name = name
Expand Down
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ hvplot
xarray
datashader
tskit
seaborn
seaborn
pre-commit
pytest
12 changes: 5 additions & 7 deletions tests/test_data_model.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import pytest
import tskit
import numpy.testing as nt
import numpy as np

import model
import utils
import numpy.testing as nt
import tskit



def single_tree_example_ts():
Expand Down Expand Up @@ -42,6 +40,7 @@ def single_tree_recurrent_mutation_example_ts():
ts = tables.tree_sequence()
return tables.tree_sequence()


def multiple_trees_example_ts():
# 2.00┊ 4 ┊ 4 ┊
# ┊ ┏━┻┓ ┊ ┏┻━┓ ┊
Expand Down Expand Up @@ -162,8 +161,7 @@ def test_single_tree_example(self):
assert len(df) == 7
nt.assert_array_equal(df.time, [0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 2.0])
nt.assert_array_equal(df.num_mutations, [1, 1, 1, 1, 1, 1, 0])
nt.assert_array_equal(df.ancestors_span, [
10, 10, 10, 10, 10, 10, -np.inf])
nt.assert_array_equal(df.ancestors_span, [10, 10, 10, 10, 10, 10, -np.inf])

def test_multiple_tree_example(self):
ts = multiple_trees_example_ts()
Expand Down

0 comments on commit 953c8e6

Please sign in to comment.