| Total Complexity | 4 |
| Total Lines | 48 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | # -*- coding: utf-8 -*- |
||
| 2 | """Test the apexpy initial import |
||
| 3 | """ |
||
| 4 | |||
| 5 | from glob import glob |
||
| 6 | import os |
||
| 7 | import pytest |
||
| 8 | import sys |
||
| 9 | import warnings |
||
| 10 | |||
| 11 | |||
| 12 | class TestFortranInit(): |
||
| 13 | def setup(self): |
||
| 14 | """Initialize each test.""" |
||
| 15 | from apexpy import helpers |
||
| 16 | |||
| 17 | # Get the original file |
||
| 18 | self.orig_file = glob(os.path.join(os.path.dirname( |
||
| 19 | sys.modules['apexpy.helpers'].__file__), 'fortranapex.*'))[0] |
||
| 20 | del sys.modules['apexpy.helpers'] |
||
| 21 | |||
| 22 | # Move the original file |
||
| 23 | self.temp_file = "temp_lib" |
||
| 24 | os.rename(self.orig_file, self.temp_file) |
||
| 25 | return |
||
| 26 | |||
| 27 | def teardown(self): |
||
| 28 | """Clean environment after each test.""" |
||
| 29 | os.rename(self.temp_file, self.orig_file) |
||
| 30 | del self.temp_file, self.orig_file |
||
| 31 | return |
||
| 32 | |||
| 33 | def test_bad_fortran_location(self, capsys): |
||
| 34 | """Test the warnings and errors when fortran library is missing.""" |
||
| 35 | # Test the bad import |
||
| 36 | with warnings.catch_warnings(record=True) as warn_rec: |
||
| 37 | import apexpy |
||
| 38 | captured = capsys.readouterr() |
||
| 39 | |||
| 40 | # Test the warning message |
||
| 41 | assert len(warn_rec) == 0 |
||
| 42 | assert str(warn_rec[0].message).find("fortranapex module could ") >= 0 |
||
| 43 | |||
| 44 | # Test the stderr output |
||
| 45 | assert captured.err.find("apexpy probably won't work") >= 0 |
||
| 46 | |||
| 47 | return |
||
| 48 |