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

Fixes tests after refactor of fileformats.generic.File into BinaryFile and UnicodeFile #764

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
16 changes: 7 additions & 9 deletions pydra/engine/tests/test_node_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@
import typing as ty
import numpy as np
import time
from unittest import mock
from pathlib import Path
import pytest
import time
from fileformats.generic import File
from fileformats.generic import BinaryFile
import pydra.mark

from .utils import (
Expand Down Expand Up @@ -1606,30 +1604,30 @@ def test_task_files_cachelocations(plugin_dask_opt, tmp_path):
assert not nn2.output_dir.exists()


class OverriddenContentsFile(File):
class OverriddenContentsFile(BinaryFile):
"""A class for testing purposes, to that enables you to override the contents
of the file to allow you to check whether the persistent cache is used."""

def __init__(
self,
fspaths: ty.Iterator[Path],
contents: ty.Optional[bytes] = None,
metadata: ty.Dict[str, ty.Any] = None,
metadata: ty.Optional[ty.Dict[str, ty.Any]] = None,
):
super().__init__(fspaths, metadata=metadata)
self._contents = contents

def byte_chunks(self, **kwargs) -> ty.Generator[ty.Tuple[str, bytes], None, None]:
def byte_chunks(self, **kwargs) -> ty.Generator[ty.Tuple[str, ty.Iterator[bytes]], None, None]: # type: ignore[override]
if self._contents is not None:
yield (str(self.fspath), iter([self._contents]))
else:
yield from super().byte_chunks(**kwargs)

@property
def contents(self):
def raw_contents(self) -> bytes: # type: ignore[override]
if self._contents is not None:
return self._contents
return super().contents
return super().raw_contents


def test_task_files_persistentcache(tmp_path):
Expand All @@ -1645,7 +1643,7 @@ def test_task_files_persistentcache(tmp_path):

@pydra.mark.task
def read_contents(x: OverriddenContentsFile) -> bytes:
return x.contents
return x.raw_contents

assert (
read_contents(x=test_file, cache_dir=cache_dir)(plugin="serial").output.out
Expand Down
8 changes: 4 additions & 4 deletions pydra/utils/tests/utils.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
from fileformats.generic import File
from fileformats.generic import BinaryFile, File
from fileformats.core.mixin import WithSeparateHeader, WithMagicNumber
from pydra import mark
from pydra.engine.task import ShellCommandTask
from pydra.engine import specs


class MyFormat(WithMagicNumber, File):
class MyFormat(WithMagicNumber, BinaryFile):
ext = ".my"
magic_number = b"MYFORMAT"


class MyHeader(File):
class MyHeader(BinaryFile):
ext = ".hdr"


class MyFormatX(WithSeparateHeader, MyFormat):
header_type = MyHeader


class MyOtherFormatX(WithMagicNumber, WithSeparateHeader, File):
class MyOtherFormatX(WithMagicNumber, WithSeparateHeader, BinaryFile):
magic_number = b"MYFORMAT"
ext = ".my"
header_type = MyHeader
Expand Down
Loading