Skip to content

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

@aburrell

Description

@aburrell

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.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions