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

ENH: Unit test for import with bad fortran compilation #74

Open
aburrell opened this issue Apr 21, 2021 · 0 comments
Open

ENH: Unit test for import with bad fortran compilation #74

aburrell opened this issue Apr 21, 2021 · 0 comments
Milestone

Comments

@aburrell
Copy link
Owner

Is your feature request related to a problem? Please describe.
The only coverage that is missing is for the warnings raised when apexpy is not correctly installed due to a failed attempt at compiling the fortran code.

Describe the solution you'd like
A unit test for this occurance.

Describe alternatives you've considered

# -*- coding: utf-8 -*-
"""Test the apexpy initial import
"""

from glob import glob
import os
import sys
import warnings


class TestFortranInit():
    def setup(self):
        """Initialize each test."""
        from apexpy import helpers  # NOQA 401

        # Get the original file
        self.orig_file = glob(os.path.join(
            os.path.dirname(sys.modules['apexpy.helpers'].__file__),
            'fortranapex*{:d}{:d}*'.format(sys.version_info.major,
                                           sys.version_info.minor)))[0]
        del sys.modules['apexpy.helpers'], helpers

        # Move the original file
        self.temp_file = "temp_lib"
        os.rename(self.orig_file, self.temp_file)
        return

    def teardown(self):
        """Clean environment after each test."""
        os.rename(self.temp_file, self.orig_file)
        del self.temp_file, self.orig_file
        return

    def test_bad_fortran_location(self, capsys):
        """Test the warnings and errors when fortran library is missing."""
        # Test the bad import
        with warnings.catch_warnings(record=True) as warn_rec:
            import apexpy  # NOQA 401
            captured = capsys.readouterr()

        # Test the warning message
        assert len(warn_rec) == 1
        assert str(warn_rec[0].message).find("fortranapex module could ") >= 0

        # Test the stderr output
        assert captured.err.find("apexpy probably won't work") >= 0

        return

Additional context
The above test doesn't work.

Reminders
This is a volunteer-driven project. Code contributions are welcome, as is help
testing new code.

@aburrell aburrell added this to the Future milestone Apr 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant