tberlok / paicos

An object-oriented Python package for analysis of (cosmological) simulations performed with Arepo
GNU General Public License v3.0
11 stars 3 forks source link

`test_non_comoving` fails #49

Closed kyleaoman closed 7 months ago

kyleaoman commented 8 months ago

I attempted to run the test suite locally and got the following failure:

_____________________________________________________________ test_non_comoving _____________________________________________________________

show = False

    def test_non_comoving(show=False):
        import paicos as pa
        import numpy as np
>       snap = pa.Snapshot(pa.data_dir, 7,
                           basename='small_non_comoving')

tests/non-comoving/test_non_comoving.py:5: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
paicos/readers/arepo_snap.py:85: in __init__
    super().__init__(basedir=basedir, snapnum=snapnum, basename=basename,
paicos/readers/paicos_readers.py:121: in __init__
    self.get_units_and_other_parameters()
paicos/readers/paicos_readers.py:190: in get_units_and_other_parameters
    arepo_time = u.def_unit(
../../.miniconda3/envs/paicos_review/lib/python3.11/site-packages/astropy/units/core.py:2618: in def_unit
    result = Unit(s, represents, namespace=namespace, doc=doc, format=format)
../../.miniconda3/envs/paicos_review/lib/python3.11/site-packages/astropy/units/core.py:2077: in __call__
    return super().__call__(
../../.miniconda3/envs/paicos_review/lib/python3.11/site-packages/astropy/units/core.py:2235: in __init__
    NamedUnit.__init__(self, st, namespace=namespace, doc=doc, format=format)
../../.miniconda3/envs/paicos_review/lib/python3.11/site-packages/astropy/units/core.py:1799: in __init__
    self._inject(namespace)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = Unit("arepo_time")
namespace = {'Histogram2DReader': <class 'paicos.readers.paicos_readers.Histogram2DReader'>, 'ImageCreator': <class 'paicos.image_...s 'paicos.readers.paicos_readers.ImageReader'>, 'LambdaCDM': <class 'astropy.cosmology.flrw.lambdacdm.LambdaCDM'>, ...}

    def _inject(self, namespace=None):
        """
        Injects the unit, and all of its aliases, in the given
        namespace dictionary.
        """
        if namespace is None:
            return

        # Loop through all of the names first, to ensure all of them
        # are new, then add them all as a single "transaction" below.
        for name in self._names:
            if name in namespace and self != namespace[name]:
>               raise ValueError(
                    f"Object with name {name!r} already exists in "
                    f"given namespace ({namespace[name]!r})."
                )
E               ValueError: Object with name 'arepo_time' already exists in given namespace (Unit("arepo_time")).

../../.miniconda3/envs/paicos_review/lib/python3.11/site-packages/astropy/units/core.py:1880: ValueError
tberlok commented 8 months ago

I have explained in some details why it fails here: https://github.com/tberlok/paicos/issues/59

The problem here is that pytest uses one single Python session to run all the tests when you do pytest at the base directory (this is why I introduced the make checks command). I have updated the error message that you get when loading several snapshots with different unit systems, so that the difficult to understand and expected astropy error message is explained.

You can check that all the tests work like this (one python session for each set of tests):

pytest tests/comoving
pytest tests/non-comoving
pytest tests/general
pytest tests/cuda-gpu

This should hopefully work.