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

1 test fails: AssertionError: assert ['second', 'first'] == ['first', 'second'] #1375

Closed
yurivict opened this issue Oct 10, 2024 · 3 comments · Fixed by #1377
Closed

1 test fails: AssertionError: assert ['second', 'first'] == ['first', 'second'] #1375

yurivict opened this issue Oct 10, 2024 · 3 comments · Fixed by #1377

Comments

@yurivict
Copy link

========================================================================================== ERRORS ===========================================================================================
______________________________________________________________________ ERROR at teardown of TestRunAllTests.test_first ______________________________________________________________________

cls = <class 'nibabel.tests.test_api_validators.TestRunAllTests'>

    @classmethod
    def teardown_class(cls):
        # Check that both validate_xxx tests got run
>       assert cls.run_tests == ['first', 'second']
E       AssertionError: assert ['second', 'first'] == ['first', 'second']
E         
E         At index 0 diff: 'second' != 'first'
E         
E         Full diff:
E           [
E         +     'second',
E               'first',
E         -     'second',
E           ]

nibabel/tests/test_api_validators.py:116: AssertionError
========================================================================================= FAILURES ==========================================================================================
__________________________________________________________________________________ TestEcatImage.test_file __________________________________________________________________________________

self = <nibabel.tests.test_ecat.TestEcatImage testMethod=test_file>

    def test_file(self):
>       assert Path(self.img.file_map['header'].filename) == Path(self.example_file)
E       AssertionError: assert PosixPath('tinypet_tmp.v') == PosixPath('/usr/ports/science/py-nibabel/work-py311/nibabel-5.3.0/nibabel/tests/data/tinypet.v')
E        +  where PosixPath('tinypet_tmp.v') = Path('tinypet_tmp.v')
E        +    where 'tinypet_tmp.v' = <nibabel.fileholders.FileHolder object at 0x3d17265d0650>.filename
E        +  and   PosixPath('/usr/ports/science/py-nibabel/work-py311/nibabel-5.3.0/nibabel/tests/data/tinypet.v') = Path('/usr/ports/science/py-nibabel/work-py311/nibabel-5.3.0/nibabel/tests/data/tinypet.v')
E        +    where '/usr/ports/science/py-nibabel/work-py311/nibabel-5.3.0/nibabel/tests/data/tinypet.v' = <nibabel.tests.test_ecat.TestEcatImage testMethod=test_file>.example_file

nibabel/tests/test_ecat.py:186: AssertionError

Version: 5.3.0
Python-3.11
FreeBSD 14.1

@effigies
Copy link
Member

The first looks like a race condition for a test suite written before parallelizing tests. Should be straightforward. The second is a bit weirder... Will have a look tomorrow.

@effigies
Copy link
Member

Okay, I really don't understand the second one.

We have:

class TestEcatImage(TestCase):
image_class = EcatImage
example_file = ecat_file
img = image_class.load(example_file)
def test_file(self):
assert Path(self.img.file_map['header'].filename) == Path(self.example_file)
assert Path(self.img.file_map['image'].filename) == Path(self.example_file)

ecat_file is evidently '/usr/ports/science/py-nibabel/work-py311/nibabel-5.3.0/nibabel/tests/data/tinypet.v'.

When we load():

nibabel/nibabel/ecat.py

Lines 1016 to 1018 in 3b1c7b3

@classmethod
def load(klass, filespec):
return klass.from_filename(filespec)

We call:

@classmethod
def from_filename(klass: type[ImgT], filename: FileSpec) -> ImgT:
file_map = klass.filespec_to_file_map(filename)
return klass.from_file_map(file_map)

which calls:

@classmethod
def filespec_to_file_map(klass, filespec: FileSpec) -> FileMap:
"""Make `file_map` for this class from filename `filespec`
Class method
Parameters
----------
filespec : str or os.PathLike
Filename that might be for this image file type.
Returns
-------
file_map : dict
`file_map` dict with (key, value) pairs of (``file_type``,
FileHolder instance), where ``file_type`` is a string giving the
type of the contained file.
Raises
------
ImageFileError
if `filespec` is not recognizable as being a filename for this
image type.
"""
try:
filenames = types_filenames(
filespec, klass.files_types, trailing_suffixes=klass._compressed_suffixes
)
except TypesFilenamesError:
raise ImageFileError(f'Filespec "{filespec}" does not look right for class {klass}')
file_map = {}
for key, fname in filenames.items():
file_map[key] = FileHolder(filename=fname)
return file_map

The only place I see to change the filename is here:

filename, found_ext, ignored, guessed_name = parse_filename(
template_fname, types_exts, trailing_suffixes, match_case
)

Would you mind adding a breakpoint() after that line, running tox -e py311-x64-none -- tests/test_ecat.py -k test_file and then

(Pdb) from pprint import pprint
(Pdb) pprint(vars())

@effigies
Copy link
Member

I've addressed the first issue. If you can provide more information on the second issue, please open a new issue referencing this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants