Skip to content

Commit 2daf48f

Browse files
committed
fixes to unittests after typing refactor of fileformats into BinaryFile and UnicodeFile
1 parent d674840 commit 2daf48f

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

pydra/engine/tests/test_node_task.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@
44
import typing as ty
55
import numpy as np
66
import time
7-
from unittest import mock
87
from pathlib import Path
98
import pytest
10-
import time
11-
from fileformats.generic import File
9+
from fileformats.generic import BinaryFile
1210
import pydra.mark
1311

1412
from .utils import (
@@ -1606,30 +1604,30 @@ def test_task_files_cachelocations(plugin_dask_opt, tmp_path):
16061604
assert not nn2.output_dir.exists()
16071605

16081606

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

16131611
def __init__(
16141612
self,
16151613
fspaths: ty.Iterator[Path],
16161614
contents: ty.Optional[bytes] = None,
1617-
metadata: ty.Dict[str, ty.Any] = None,
1615+
metadata: ty.Optional[ty.Dict[str, ty.Any]] = None,
16181616
):
16191617
super().__init__(fspaths, metadata=metadata)
16201618
self._contents = contents
16211619

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

16281626
@property
1629-
def contents(self):
1627+
def raw_contents(self) -> bytes: # type: ignore[override]
16301628
if self._contents is not None:
16311629
return self._contents
1632-
return super().contents
1630+
return super().raw_contents
16331631

16341632

16351633
def test_task_files_persistentcache(tmp_path):
@@ -1645,7 +1643,7 @@ def test_task_files_persistentcache(tmp_path):
16451643

16461644
@pydra.mark.task
16471645
def read_contents(x: OverriddenContentsFile) -> bytes:
1648-
return x.contents
1646+
return x.raw_contents
16491647

16501648
assert (
16511649
read_contents(x=test_file, cache_dir=cache_dir)(plugin="serial").output.out

pydra/utils/tests/utils.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
from fileformats.generic import File
1+
from fileformats.generic import BinaryFile, File
22
from fileformats.core.mixin import WithSeparateHeader, WithMagicNumber
33
from pydra import mark
44
from pydra.engine.task import ShellCommandTask
55
from pydra.engine import specs
66

77

8-
class MyFormat(WithMagicNumber, File):
8+
class MyFormat(WithMagicNumber, BinaryFile):
99
ext = ".my"
1010
magic_number = b"MYFORMAT"
1111

1212

13-
class MyHeader(File):
13+
class MyHeader(BinaryFile):
1414
ext = ".hdr"
1515

1616

1717
class MyFormatX(WithSeparateHeader, MyFormat):
1818
header_type = MyHeader
1919

2020

21-
class MyOtherFormatX(WithMagicNumber, WithSeparateHeader, File):
21+
class MyOtherFormatX(WithMagicNumber, WithSeparateHeader, BinaryFile):
2222
magic_number = b"MYFORMAT"
2323
ext = ".my"
2424
header_type = MyHeader

0 commit comments

Comments
 (0)