コード例 #1
0
ファイル: test_clib_loading.py プロジェクト: weiji14/pygmt
def test_load_libgmt_fails(monkeypatch):
    """
    Test that GMTCLibNotFoundError is raised when GMT's shared library cannot
    be found.
    """
    with monkeypatch.context() as mpatch:
        mpatch.setattr(sys, "platform", "win32")  # pretend to be on Windows
        mpatch.setattr(subprocess, "check_output",
                       lambda cmd, encoding: "libfakegmt.so")
        with pytest.raises(GMTCLibNotFoundError):
            check_libgmt(load_libgmt())
コード例 #2
0
ファイル: test_clib_loading.py プロジェクト: weiji14/pygmt
def test_check_libgmt():
    """
    Make sure check_libgmt fails when given a bogus library.
    """
    libgmt = FakedLibGMT("/path/to/libgmt.so")
    msg = (
        # pylint: disable=protected-access
        f"Error loading '{libgmt._name}'. "
        "Couldn't access function GMT_Create_Session. "
        "Ensure that you have installed an up-to-date GMT version 6 library. "
        "Please set the environment variable 'GMT_LIBRARY_PATH' to the "
        "directory of the GMT 6 library.")
    with pytest.raises(GMTCLibError, match=msg):
        check_libgmt(libgmt)
コード例 #3
0
ファイル: test_clib_loading.py プロジェクト: weiji14/pygmt
def test_load_libgmt_with_a_bad_library_path(monkeypatch):
    """
    Test that loading still works when given a bad library path.
    """
    # Set a fake "GMT_LIBRARY_PATH"
    monkeypatch.setenv("GMT_LIBRARY_PATH", "/not/a/real/path")
    assert check_libgmt(load_libgmt()) is None
コード例 #4
0
ファイル: test_clib_loading.py プロジェクト: weiji14/pygmt
 def test_brokenlib_brokenlib_workinglib(self, mock_ctypes):  # pylint: disable=unused-argument
     """
     Case 6: repeating broken libraries + working library.
     """
     lib_fullnames = [
         self.faked_libgmt1, self.faked_libgmt1, self.loaded_libgmt
     ]
     assert check_libgmt(load_libgmt(lib_fullnames=lib_fullnames)) is None
コード例 #5
0
ファイル: test_clib_loading.py プロジェクト: weiji14/pygmt
 def test_workinglib_brokenlib_invalidpath(self, mock_ctypes):  # pylint: disable=unused-argument
     """
     Case 5: working library + broken library + invalid path.
     """
     lib_fullnames = [
         self.loaded_libgmt, self.faked_libgmt1, self.invalid_path
     ]
     assert check_libgmt(load_libgmt(lib_fullnames=lib_fullnames)) is None
コード例 #6
0
def test_load_libgmt():
    "Test that loading libgmt works and doesn't crash."
    check_libgmt(load_libgmt())
コード例 #7
0
def test_check_libgmt():
    "Make sure check_libgmt fails when given a bogus library"
    with pytest.raises(GMTCLibError):
        check_libgmt(dict())