Skip to content

Commit

Permalink
Merge pull request #14 from nipype/pkg-gen-test
Browse files Browse the repository at this point in the history
Add package generation test
  • Loading branch information
tclose authored Mar 16, 2024
2 parents ac0297d + 0694d7b commit 7d6ff89
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ jobs:
- name: Unset header
# checkout@v2 adds a header that makes branch protection report errors
# because the Github action bot is not a collaborator on the repo
run: git config --local --unset http.https://github.com/.extraheader
run: |
git config --local --unset http.https://github.com/.extraheader
git config --global init.defaultBranch main
git config --global user.email "[email protected]"
git config --global user.name "Dummy User"
- name: Fetch tags
run: git fetch --prune --unshallow
Expand Down
11 changes: 7 additions & 4 deletions nipype2pydra/pkg_gen/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
import shutil
import string
from pathlib import Path
import inspect
import attrs
from warnings import warn
import requests
from operator import itemgetter
import yaml
import black.parsing
import fileformats.core.utils
import fileformats.core
import fileformats.core.mixin
from fileformats.generic import File, Directory
from fileformats.medimage import Nifti1, NiftiGz, Bval, Bvec
Expand Down Expand Up @@ -261,7 +262,7 @@ def generate_yaml_spec(self) -> str:
def type2str(tp):
if tp in non_mime:
return tp.__name__
return fileformats.core.utils.to_mime(tp, official=False)
return fileformats.core.to_mime(tp, official=False)

tests, doctests = self._gen_tests(
doctest_blocks, input_types, output_types, output_templates
Expand Down Expand Up @@ -481,9 +482,10 @@ def combine_types(type_, prev_type):
if ty.get_origin(type_) is list:
as_list = True
type_ = ty.get_args(type_)[0]
if issubclass(type_, prev_type):
both_classes = inspect.isclass(type_) and inspect.isclass(prev_type)
if both_classes and issubclass(type_, prev_type):
combined = type_
elif issubclass(prev_type, type_):
elif both_classes and issubclass(prev_type, type_):
combined = prev_type
else:
if ty.get_origin(prev_type) is ty.Union:
Expand Down Expand Up @@ -563,6 +565,7 @@ def _fields_stub(cls, name, category_class, values=None):

def download_tasks_template(output_path: Path):
"""Downloads the latest pydra-template to the output path"""
output_path.parent.mkdir(parents=True, exist_ok=True)

release_url = (
"https://api.github.com/repos/nipype/pydra-tasks-template/releases/latest"
Expand Down
17 changes: 17 additions & 0 deletions nipype2pydra/tests/test_pkg_gen.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from nipype2pydra.cli.pkg_gen import pkg_gen
from conftest import show_cli_trace


def test_pkg_gen(cli_runner, tmp_path):
outputs_dir = tmp_path / "output-dir"
outputs_dir.mkdir()

result = cli_runner(
pkg_gen,
[
str(outputs_dir),
"--work-dir",
str(tmp_path / "work-dir"),
],
)
assert result.exit_code == 0, show_cli_trace(result)

0 comments on commit 7d6ff89

Please sign in to comment.