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

Fix tests #16

Merged
merged 4 commits into from
Mar 4, 2022
Merged

Fix tests #16

merged 4 commits into from
Mar 4, 2022

Conversation

jeanconn
Copy link
Contributor

@jeanconn jeanconn commented Mar 3, 2022

Description

Fix tests.

They were failing due to the formatting of the debug print and if called with pytest without an __init__.py in the testing directory, these seemed to be running against the installed code instead of the local files.

See also #17 for more on the exception.

Testing

  • Passes unit tests called with pytest from linux HEAD flight and test
  • [n/a] Functional testing

@jeanconn jeanconn requested a review from taldcroft March 3, 2022 01:14
@jeanconn jeanconn force-pushed the fix-tests branch 2 times, most recently from f996be0 to eecb145 Compare March 3, 2022 14:12
@jeanconn jeanconn changed the base branch from master to fix-logger-error March 3, 2022 14:12
@taldcroft
Copy link
Member

taldcroft commented Mar 3, 2022

Absolute imports really should work. This is the recommended way of writing tests and astropy does this exclusively. They did for me, I added an import find_attitude and printed the __file__

kady$ pytest find_attitude -v --pdb -x -k test_nothingno -s
================================================================== test session starts ===================================================================
platform linux -- Python 3.8.12, pytest-6.2.5, py-1.10.0, pluggy-1.0.0 -- /proj/sot/ska3/test/bin/python
cachedir: .pytest_cache
hypothesis profile 'default' -> database=DirectoryBasedExampleDatabase('/data/baffin/tom/git/find_attitude/.hypothesis/examples')
rootdir: /data/baffin/tom/git/find_attitude
plugins: anyio-2.2.0, hypothesis-6.29.3, arraydiff-0.3, astropy-header-0.1.2, cov-3.0.0, doctestplus-0.11.2, filter-subpackage-0.1.1, mock-3.6.1, openfiles-0.5.0, remotedata-0.3.3
collecting ...

/data/baffin/tom/git/find_attitude/find_attitude/__init__.py  <======

@jeanconn jeanconn changed the title Fix tests Pytest fixes Mar 3, 2022
@taldcroft
Copy link
Member

Fix the Testing description above so it accurately represents what you actually tested.

@jeanconn jeanconn changed the base branch from fix-logger-error to master March 3, 2022 14:18
@taldcroft
Copy link
Member

taldcroft commented Mar 3, 2022

OK, so once again I had a tests/__init__.py hanging around in my repo that seems to have disappeared at some point, and that is probably the reason why things are working for me and not @jeanconn . @javierggt did some of your namespace stuff remove those? When did they disappear?

@jeanconn
Copy link
Contributor Author

jeanconn commented Mar 3, 2022

Right. Though in this case, python setup.py test did seem to work without the __init__.py in the tests directory. Otherwise pytest output showed calls to the installed module (here a run in ska3-next test):

jeanconn-fido> pytest
============================================= test session starts ==============================================
platform linux -- Python 3.8.12, pytest-6.2.5, py-1.10.0, pluggy-1.0.0
rootdir: /proj/sot/ska/jeanproj/git/find_attitude
plugins: anyio-2.2.0, hypothesis-6.29.3, arraydiff-0.3, astropy-header-0.1.2, cov-3.0.0, doctestplus-0.11.2, filter-subpackage-0.1.1, mock-3.6.1, openfiles-0.5.0, remotedata-0.3.3
collected 6 items                                                                                              

find_attitude/tests/test_find_attitude.py FFFFFF                                                                                    [100%]

================================================================ FAILURES =================================================================
_______________________________________________________ test_overlapping_distances ________________________________________________________

tolerance = 3.0

    def test_overlapping_distances(tolerance=3.0):
        """
        Test a case where distance 5-7 = 864.35 and 5-1 is 865.808
        """
        global ra, dec, roll, stars, agasc_id_star_maps, g_geom_match, g_dist_match
        ra, dec, roll = (131.1371559426714, 65.25369723989581, 112.4351393383257)  # 3 overlaps, 3.0 tol
        stars = get_stars(ra, dec, roll, sigma_1axis=0.004, sigma_mag=0.2, brightest=True)
    
>       solutions = find_attitude_solutions(stars)

find_attitude/tests/test_find_attitude.py:69: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/proj/sot/ska3/test/lib/python3.8/site-packages/find_attitude/find_attitude.py:567: in find_attitude_solutions
    agasc_id_star_maps = find_all_matching_agasc_ids(stars['YAG'], stars['ZAG'], stars['MAG_ACA'],
/proj/sot/ska3/test/lib/python3.8/site-packages/find_attitude/find_attitude.py:442: in find_all_matching_agasc_ids
    agasc_id_star_maps = find_matching_agasc_ids(stars, agasc_pairs_file,
/proj/sot/ska3/test/lib/python3.8/site-packages/find_attitude/find_attitude.py:405: in find_matching_agasc_ids
    logger.debug(n0, n1, ed)
/proj/sot/ska3/test/lib/python3.8/logging/__init__.py:1434: in debug
    self._log(DEBUG, msg, args, **kwargs)
/proj/sot/ska3/test/lib/python3.8/logging/__init__.py:1589: in _log
    self.handle(record)
/proj/sot/ska3/test/lib/python3.8/logging/__init__.py:1599: in handle
    self.callHandlers(record)
/proj/sot/ska3/test/lib/python3.8/logging/__init__.py:1661: in callHandlers
    hdlr.handle(record)
/proj/sot/ska3/test/lib/python3.8/logging/__init__.py:954: in handle
    self.emit(record)
/proj/sot/ska3/test/lib/python3.8/site-packages/_pytest/logging.py:331: in emit
    super().emit(record)
/proj/sot/ska3/test/lib/python3.8/site-packages/pyyaks/logger.py:62: in emit_newline_optional
    handler.handleError(record)
/proj/sot/ska3/test/lib/python3.8/site-packages/pyyaks/logger.py:49: in emit_newline_optional
    msg = handler.format(record)
/proj/sot/ska3/test/lib/python3.8/logging/__init__.py:929: in format
    return fmt.format(record)
/proj/sot/ska3/test/lib/python3.8/site-packages/_pytest/logging.py:92: in format
    return super().format(record)
/proj/sot/ska3/test/lib/python3.8/logging/__init__.py:668: in format
    record.message = record.getMessage()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <LogRecord: find_attitude, 10, /proj/sot/ska3/test/lib/python3.8/site-packages/find_attitude/find_attitude.py, 405, "1130890432">

    def getMessage(self):
        """
        Return the message for this LogRecord.
    
        Return the message for this LogRecord after merging any user-supplied
        arguments with the message.
        """
        msg = str(self.msg)
        if self.args:
>           msg = msg % self.args
E           TypeError: not all arguments converted during string formattin

@taldcroft
Copy link
Member

From some quick digging it looks like the tests/__init__.py just never made it into the repo, I only had a copy laying around in my own repo directory. Sigh.

@taldcroft
Copy link
Member

So just add __init__.py and revert the relative import.

@jeanconn
Copy link
Contributor Author

jeanconn commented Mar 3, 2022

I thought the relative import was not required but kinda matched what we've been using everyplace else.

@taldcroft
Copy link
Member

We should use absolute imports going forward when possible.

@taldcroft
Copy link
Member

taldcroft commented Mar 3, 2022

Is this the place to fix the host of Deprecation warnings coming from sherpa and ipyparallel and (some-unnamed-package) in ska3-next?

find_attitude/tests/test_find_attitude.py::test_overlapping_distances
  /proj/sot/ska3/test/lib/python3.8/site-packages/sherpa/sim/__init__.py:222: DeprecationWarning: `np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.
  Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
    _tol = numpy.finfo(numpy.float).eps

find_attitude/tests/test_find_attitude.py::test_at_times
  /proj/sot/ska3/test/lib/python3.8/site-packages/ipyparallel/client/view.py:8: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
    import imp

find_attitude/tests/test_find_attitude.py: 296 warnings
  <template>:16: DeprecationWarning: 'soft_unicode' has been renamed to 'soft_str'. The old name will be removed in MarkupSafe 2.1.

@jeanconn
Copy link
Contributor Author

jeanconn commented Mar 3, 2022

Right, I was asking that in fb9d577 . Do we just stick them in the pytest ini here? And are they fixed in new sherpa or should we just submit a PR?

@jeanconn jeanconn changed the title Pytest fixes Fix tests Mar 3, 2022
@taldcroft
Copy link
Member

And are they fixed in new sherpa

Yes, fixed in 4.14.0. I actually found the sherpa PR's for this earlier.

Copy link
Member

@taldcroft taldcroft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine now. It would be nice to have some way to remember to take out those ignore lines when we upgrade to sherpa 4.14. Maybe once this is merged you can make a PR that removes them which we have hanging around and might eventually notice.

@jeanconn
Copy link
Contributor Author

jeanconn commented Mar 4, 2022

I also didn't think the pytest.ini ignores would do anything in ska_testr?

@jeanconn jeanconn merged commit 21bdc67 into master Mar 4, 2022
@jeanconn jeanconn deleted the fix-tests branch March 4, 2022 14:56
@javierggt javierggt mentioned this pull request Mar 30, 2022
@javierggt javierggt mentioned this pull request Aug 3, 2022
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 this pull request may close these issues.

2 participants