Skip to content
This repository has been archived by the owner on Aug 8, 2024. It is now read-only.

Commit

Permalink
Merge pull request #38 from scalableminds/matrix_tests
Browse files Browse the repository at this point in the history
Add matrix tests to GitHub Actions CI
  • Loading branch information
hotzenklotz authored Dec 7, 2020
2 parents d9354e0 + abb8c7d commit e66cb52
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 45 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Build and Upload Python Package

on:
release:
types:
- created

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Set up Python
uses: actions/setup-python@v1
with:
python-version: '3.7'

- name: Install dependencies
run: |
python -m pip install poetry
poetry install
- name: Build and publish
env:
PYPI_SCM_USERNAME: ${{ secrets.PYPI_USERNAME }}
PYPI_SCM_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
poetry publish --build -u $PYPI_SCM_USERNAME -p $PYPI_SCM_PASSWORD
23 changes: 13 additions & 10 deletions .github/workflows/python-module.yml → .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,36 +1,39 @@
name: Test and Upload Python Package
name: Test Python Package

on: [push]

jobs:
deploy:
test:
runs-on: ubuntu-latest
strategy:
max-parallel: 4
matrix:
python-version: [3.6, 3.7, 3.8]

steps:
- uses: actions/checkout@v1
- name: Set up Python
uses: actions/setup-python@v1
with:
python-version: '3.6'
python-version: ${{ matrix.python-version }}
architecture: 'x64' # (x64 or x86)

- name: Install dependencies
run: |
python -m pip install poetry
poetry install
- name: Check formatting
run: |
poetry run black --check wknml tests examples
- name: Unit Tests
run: |
mkdir -p testoutput
poetry run pytest tests
- name: Check Documentation for updates
run: |
poetry run pydoc-markdown -m wknml --render-toc > docs/ci_test.md
diff docs/ci_test.md docs/wknml.md
rm docs/ci_test.md
- name: Build and publish
if: startsWith(github.event.ref, 'refs/tags')
env:
PYPI_SCM_USERNAME: ${{ secrets.PYPI_USERNAME }}
PYPI_SCM_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
poetry publish --build -u $PYPI_SCM_USERNAME -p $PYPI_SCM_PASSWORD
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# wknml
[![PyPI version](https://img.shields.io/pypi/v/wknml)](https://pypi.python.org/pypi/wknml)
[![Supported Python Versions](https://img.shields.io/pypi/pyversions/wknml.svg)](https://pypi.python.org/pypi/wknml)
[![Build Status](https://img.shields.io/github/workflow/status/scalableminds/wknml/Test%20Python%20Package/master)](https://github.com/scalableminds/wknml/actions?query=workflow%3A%22Test+Python+Package%22)
[![Documentation](https://img.shields.io/badge/docs-passing-brightgreen.svg)](https://github.com/scalableminds/wknml/blob/master/docs/wknml.md)
[![Code Style](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)


Python library for working with [webKnossos](https://webknossos.org) [NML files](https://docs.webknossos.org/reference/data_formats#nml).
Python library for working with [webKnossos](https://webknossos.org) [skeleton annotation files (NML)](https://docs.webknossos.org/reference/data_formats#nml).

## Installation
To use wknml, you need to have Python 3.6+ (on the system or with Anaconda) installed.
wknml requires Python 3.6+

```
pip install wknml
Expand Down
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
[tool.poetry]
name = "wknml"
version = "1.0.0"
version = "1.0.1"
description = "Python package to work with webKnossos NML skeleton files"
authors = ["scalable minds <[email protected]>"]
readme = "README.md"
repository = "https://github.com/scalableminds/wknml"
license = "MIT"

[tool.poetry.dependencies]
Expand Down
Binary file removed testdata/complex_dataset.nml.pickle
Binary file not shown.
Binary file removed testdata/dataset.nml.pickle
Binary file not shown.
11 changes: 0 additions & 11 deletions tests/refresh_snapshots.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
import wknml
import pickle
from tests.test_snapshot_readandwrite import INPUT_FILES, OUTPUT_FILES, SNAPSHOT_FILES


def save_snapshot_pickle_read_and_write():
for i in range(0, len(INPUT_FILES)):
input_file = INPUT_FILES[i]
output_file = SNAPSHOT_FILES[i]
parsed = wknml.parse_nml(input_file)
with open(output_file + ".pickle", "wb") as f:
pickle.dump(parsed, f)


def save_snapshot_nml_read_and_write():
for i in range(0, len(INPUT_FILES)):
input_file = INPUT_FILES[i]
Expand All @@ -22,5 +12,4 @@ def save_snapshot_nml_read_and_write():


if __name__ == "__main__":
save_snapshot_pickle_read_and_write()
save_snapshot_nml_read_and_write()
36 changes: 27 additions & 9 deletions tests/test_nml_generation.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from pathlib import Path
import pickle

import pytest
import filecmp
Expand Down Expand Up @@ -36,23 +37,40 @@ def test_generate_nml():
def test_no_default_values_written():
input_file_name = "testdata/nml_without_default_values.nml"
output_file_name = "testoutput/nml_without_default_values.nml"

# read and write the test file
with open(input_file_name, "r") as file:
test_nml = parse_nml(file)
with open(output_file_name, "wb") as output_file:
write_nml(file=output_file, nml=test_nml)

with open(output_file_name, "wb") as output_file:
write_nml(file=output_file, nml=test_nml)

# read the written testfile and compare the content
with open(input_file_name, "r") as file:
test_nml = parse_nml(file)
with open(output_file_name, "r") as output_file:
test_result_nml = parse_nml(output_file)
with open(output_file_name, "r") as output_file:
test_result_nml = parse_nml(output_file)

assert (
test_nml == test_result_nml
), "The testdata file and the testoutput file do not have the same content."
assert (
test_nml == test_result_nml
), "The testdata file and the testoutput file do not have the same content."

# test if both files have the same content
assert filecmp.cmp(
input_file_name, output_file_name
), "The testdata and the testoutput file do not have the same content."


def test_pickle_serialization():
# Test if NML objects can be serialized & deserialized with pickle
input_file_name = "testdata/nml_without_default_values.nml"
output_file_name = "testoutput/nml_without_default_values.nml.pickle"

with open(input_file_name, "r") as file:
test_nml = parse_nml(file)

with open(output_file_name, "wb") as output_file:
pickle.dump(test_nml, output_file)

with open(output_file_name, "rb") as input_file:
new_nml = pickle.load(input_file)

assert test_nml == new_nml
17 changes: 6 additions & 11 deletions tests/test_snapshot_readandwrite.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,25 @@ def test_read_and_write_and_read():
for i in range(0, len(INPUT_FILES)):
input_file = INPUT_FILES[i]
output_file = OUTPUT_FILES[i]

first = wknml.parse_nml(input_file)

with open(output_file, "wb") as f:
wknml.write_nml(f, first)

second = wknml.parse_nml(output_file)
assert first == second


def test_snapshot_read_and_compare_pickle():
for i in range(0, len(INPUT_FILES)):
input_file = INPUT_FILES[i]
snapshot_file = SNAPSHOT_FILES[i]
output_file = OUTPUT_FILES[i]
parsed = wknml.parse_nml(input_file)
with open(output_file + ".pickle.cmp", "wb") as f:
pickle.dump(parsed, f)
assert filecmp.cmp(snapshot_file + ".pickle", output_file + ".pickle.cmp")


def test_snapshot_read_and_compare_nml():
for i in range(0, len(INPUT_FILES)):
input_file = INPUT_FILES[i]
snapshot_file = SNAPSHOT_FILES[i]
output_file = OUTPUT_FILES[i]

parsed = wknml.parse_nml(input_file)

with open(output_file, "wb") as f:
wknml.write_nml(f, parsed)

assert filecmp.cmp(snapshot_file + ".snapshot", output_file)

0 comments on commit e66cb52

Please sign in to comment.