emanuega / MERlin

MERlin is an extensible analysis pipeline applied to decoding MERFISH data
MIT License
35 stars 30 forks source link

How to run the tests? #35

Open HazenBabcock opened 4 years ago

HazenBabcock commented 4 years ago

It isn't clear what needs to be done to get the tests to run. Do I need to do anything beyond installing the project and all it's dependencies?

Also every test is failing with the following: ` __ ERROR at teardown of test_remove_overlapping_cells __

item =

@pytest.mark.hookwrapper
@pytest.mark.trylast
def pytest_runtest_teardown(item):
    """
    Hook called after each test tear down, to process any pending events and
    avoiding leaking events to the next test. Also, if exceptions have
    been captured during fixtures teardown, fail the test.
    """
    _process_events()
    _close_widgets(item)
    _process_events()
    yield
    _process_events()
  capture_enabled = _is_exception_capture_enabled(item)

../../../pyenv/mydev/lib/python3.6/site-packages/pytestqt/plugin.py:156:


item =

def _is_exception_capture_enabled(item):
    """returns if exception capture is disabled for the given test item.
    """
  disabled = item.get_marker('qt_no_exception_capture') or \

item.config.getini('qt_no_exception_capture') E AttributeError: 'Function' object has no attribute 'get_marker'

../../../pyenv/mydev/lib/python3.6/site-packages/pytestqt/exceptions.py:81: AttributeError

`

Which I think is actually an issue with pytest or pytest-cov. Is pytest the recommended way to run the tests?

` $ pip list | grep pytest

pytest 5.3.1 pytest-cov 2.8.1
pytest-faulthandler 1.5.0
pytest-forked 0.2
pytest-mock 1.10.0
pytest-qt 2.3.1
pytest-remotedata 0.3.2
`

emanuega commented 4 years ago

The tests can be run by executing pytest from the project root directory. The tests should run successfully after the project and the additional dependencies are installed. I upgraded my pytest and pytest-cov to the latest versions to match your environment and I was unable to reproduce the error you see. However, when I then installed pytest-qt 2.3.1 the error came up. I'd recommend either upgrading pytest-qt to the latest version or unistalling it.

emanuega commented 4 years ago

To run the tests you will also need the .merlinenv file located in your user home directed to specify the paths to the analysis results, data, and the parameters. For the tests these directories can be empty. I need to update the documentation since the documentation still specifies that this should be .env. You can create the .merlinenv file using the command (including the . at the end):

merlin --configure .

HazenBabcock commented 4 years ago

Thanks for the help, it is mostly working now except for test_spatialfeatures where two tests are failing. This is the output, apologies for it being wider than this box.

/home/hbabcock/pyenv/mydev/lib/python3.6/site-packages/_pytest/config/__init__.py:337: PytestConfigWarning: pytest-faulthandler plugin has been merged into the core, please remove it from your requirements.
  name.replace("_", "-")
============================= test session starts ==============================
platform linux -- Python 3.6.8, pytest-5.3.1, py-1.5.3, pluggy-0.13.1
PyQt5 5.10.1 -- Qt runtime 5.10.1 -- Qt compiled 5.10.1
rootdir: /home/hbabcock/Code/MERlin
plugins: forked-0.2, remotedata-0.3.2, mock-1.10.0, qt-3.3.0, faulthandler-1.5.0, cov-2.8.1
collected 96 items                                                             

test/test_barcode_database.py ..........                                 [ 10%]
test/test_binary_utils.py ..                                             [ 12%]
test/test_codebook.py ...........                                        [ 23%]
test/test_core.py .....................                                  [ 45%]
test/test_dataorganization.py ..........                                 [ 56%]
test/test_dataportal.py ............                                     [ 68%]
test/test_dataset.py ...                                                 [ 71%]
test/test_image_reader.py .                                              [ 72%]
test/test_merfish.py .                                                   [ 73%]
test/test_plotting.py ..                                                 [ 76%]
test/test_snakemake.py .....                                             [ 81%]
test/test_spatialfeature.py ...........FF.....                           [100%]

=================================== FAILURES ===================================
________________ test_feature_hdf5_db_read_write_delete_one_fov ________________

single_task = <merlin.analysis.testtask.SimpleAnalysisTask object at 0x7f5b60073e10>
simple_merfish_data = <merlin.core.dataset.MERFISHDataSet object at 0x7f5bf8b102e8>

    def test_feature_hdf5_db_read_write_delete_one_fov(
            single_task, simple_merfish_data):
        featureDB = spatialfeature.HDF5SpatialFeatureDB(
            simple_merfish_data, single_task)
        featureDB.write_features([feature1, feature2], fov=0)
>       readFeatures = featureDB.read_features(fov=0)

test/test_spatialfeature.py:89: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
merlin/util/spatialfeature.py:499: in read_features
    self._load_feature_from_hdf5_group(featureGroup[k]))
merlin/util/spatialfeature.py:455: in _load_feature_from_hdf5_group
    zGroup['p_' + str(p)]))
merlin/util/spatialfeature.py:442: in _load_geometry_from_hdf5_group
    return geometry.shape(geometryDict)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

context = {'coordinates': array([[[1., 1.],
        [1., 2.],
        [2., 2.],
        [2., 1.],
        [1., 1.]]]), 'type': 'Polygon'}

    def shape(context):
        """Returns a new, independent geometry with coordinates *copied* from the
        context.
        """
        if hasattr(context, "__geo_interface__"):
            ob = context.__geo_interface__
        else:
            ob = context
        geom_type = ob.get("type").lower()
        if geom_type == "point":
            return Point(ob["coordinates"])
        elif geom_type == "linestring":
            return LineString(ob["coordinates"])
        elif geom_type == "polygon":
>           if not ob["coordinates"]:
E           ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

../../pyenv/mydev/lib/python3.6/site-packages/Shapely-1.7a2-py3.6-linux-x86_64.egg/shapely/geometry/geo.py:35: ValueError
_____________ test_feature_hdf5_db_read_write_delete_multiple_fov ______________

single_task = <merlin.analysis.testtask.SimpleAnalysisTask object at 0x7f5b580a2320>
simple_merfish_data = <merlin.core.dataset.MERFISHDataSet object at 0x7f5bf8b102e8>

    def test_feature_hdf5_db_read_write_delete_multiple_fov(
            single_task, simple_merfish_data):
        tempFeature2 = spatialfeature.SpatialFeature(
            [[geometry.Polygon(testCoords2)]], 1)
        featureDB = spatialfeature.HDF5SpatialFeatureDB(
            simple_merfish_data, single_task)
>       featureDB.write_features([feature1, tempFeature2])

test/test_spatialfeature.py:112: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
merlin/util/spatialfeature.py:472: in write_features
    self.write_features(currentFeatures, currentFOV)
merlin/util/spatialfeature.py:483: in write_features
    fov)
merlin/util/spatialfeature.py:422: in _save_feature_to_hdf5_group
    featureGroup = h5Group.create_group(featureKey)
../../pyenv/mydev/lib/python3.6/site-packages/h5py/_hl/group.py:50: in create_group
    gid = h5g.create(self.id, name, lcpl=lcpl)
h5py/_objects.pyx:54: in h5py._objects.with_phil.wrapper
    ???
h5py/_objects.pyx:55: in h5py._objects.with_phil.wrapper
    ???
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

>   ???
E   ValueError: Unable to create group (name already exists)

h5py/h5g.pyx:151: ValueError
=============================== warnings summary ===============================
/home/hbabcock/pyenv/mydev/lib/python3.6/site-packages/_pytest/mark/structures.py:327
/home/hbabcock/pyenv/mydev/lib/python3.6/site-packages/_pytest/mark/structures.py:327
  /home/hbabcock/pyenv/mydev/lib/python3.6/site-packages/_pytest/mark/structures.py:327: PytestUnknownMarkWarning: Unknown pytest.mark.slowtest - is this a typo?  You can register custom marks to avoid this warning - for details, see https://docs.pytest.org/en/latest/mark.html
    PytestUnknownMarkWarning,

/home/hbabcock/pyenv/mydev/lib/python3.6/site-packages/_pytest/mark/structures.py:327
  /home/hbabcock/pyenv/mydev/lib/python3.6/site-packages/_pytest/mark/structures.py:327: PytestUnknownMarkWarning: Unknown pytest.mark.fullrun - is this a typo?  You can register custom marks to avoid this warning - for details, see https://docs.pytest.org/en/latest/mark.html
    PytestUnknownMarkWarning,

-- Docs: https://docs.pytest.org/en/latest/warnings.html
============= 2 failed, 94 passed, 3 warnings in 91.83s (0:01:31) ==============
emanuega commented 4 years ago

This issue seems to come from shapely commit f1a5a3f28a where they use an if statement to determine if coordinates is null, which doesn't work for numpy arrays. I'd suggest rolling back shapely to 1.6.4.post2 and I'll ask them to change this in shapely. The second error might come from it failing to clean up properly after the first task fails, but if it persists I can look into it too.

HazenBabcock commented 4 years ago

Do you know what might get left behind? I assumed it was a HDF5 file so I searched the project directory for *.h5 and *.hdf5 but didn't find anything.

emanuega commented 4 years ago

Is it narrowed down to this one failed test now? All the temporary test files are saved within subdirectories of the test folder, so if you delete everything in the folder that was not part of the git repository it should delete anything that might have been left behind. The previous test asserts that the spatial feature database is empty so if test_feature_hdf5_db_read_write_delete_one_fov is passing it could be a different problem.

The spatial features are saved into a file with .hdf5 extension.

Can you list the modules you have installed? I'm particularly interested in the version of h5py and pytables.

HazenBabcock commented 4 years ago

Okay I didn't read what you wrote carefully enough. It does look like the second test failure is due to the shapely failure. I haven't tried the shapely version you suggested yet, I thought I might pass over that for now and just address the second failure but that doesn't look possible.

I have h5py 2.10.0 and tables 3.6.1. I think these are the most updated available via pip.

emanuega commented 4 years ago

When I looked into the shapely source code it looked like the line that is causing the problem is new in 1.7a2. I'll update the merlin requirements.txt file to indicate that shapely version 1.7a2 shouldn't be used with merlin so that other users can avoid this problem.

HazenBabcock commented 4 years ago

All the tests are passing now using shapely 1.6.4.post2. Not sure if you want to leave this issue open as a reminder about the shapely requirement or not.