Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 17 additions & 20 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ env:
- BUILD_DOCS=false
- DEPLOY_DOCS=false
- DEPLOY_PYPI=false
- CONDA_REQUIREMENTS="requirements.txt"
# Need the dev channel to get development builds of GMT 6
- CONDA_FLAGS="--yes --quiet -c conda-forge -c conda-forge/label/dev"
- CONDA_FLAGS="--yes --quiet -c conda-forge/label/dev"

matrix:
# Build under the following configurations
Expand All @@ -40,25 +41,20 @@ matrix:
- BUILD_DOCS=true
- DEPLOY_DOCS=true
- DEPLOY_PYPI=true
#- os: osx
#env:
#- PYTHON=3.5
#- os: osx
#env:
#- PYTHON=3.6
#- COVERAGE=true
#- BUILD_DOCS=true
- os: osx
env:
- PYTHON=3.6
- COVERAGE=true
- BUILD_DOCS=true

before_install:
# Get Miniconda from Continuum
# Need to source the script to set the PATH variable in this environment
# (not the scripts environment)
- source ci/install-miniconda.sh
- conda update conda $CONDA_FLAGS
- conda create --name testenv python=$PYTHON pip $CONDA_FLAGS
- source activate testenv
# Install dependencies
- conda install --file requirements.txt $CONDA_FLAGS
# Get the Fatiando CI scripts
- git clone https://github.com/fatiando/continuous-integration.git
# Download and install miniconda and setup dependencies
# Need to source the script to set the PATH variable globaly
- source continuous-integration/travis/setup-miniconda.sh
# Install GMT from the dev channel
- conda install --yes --quiet -c conda-forge/label/dev gmt=6.0.0a*
- if [ "$COVERAGE" == "true" ]; then
pip install codecov codacy-coverage codeclimate-test-reporter;
fi
Expand All @@ -76,10 +72,11 @@ script:
make check;
fi
# Run the test suite
# Make pytest report any captured output on stdout or stderr
- if [ "$COVERAGE" == "true" ]; then
make coverage;
make coverage PYTEST_EXTRA="-r P";
else
make test;
make test PYTEST_EXTRA="-r P";
fi
# Build the documentation
- if [ "$BUILD_DOCS" == "true" ]; then
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Build, package, test, and clean

TESTDIR=tmp-test-dir-with-unique-name
PYTEST_ARGS=--doctest-modules -v --pyargs
PYTEST_EXTRA=
PYTEST_ARGS=--doctest-modules -v --pyargs $(PYTEST_EXTRA)
PYTEST_COV_ARGS=--cov-config=../.coveragerc --cov-report=term-missing
CHECK_FILES=gmt setup.py

Expand Down
24 changes: 12 additions & 12 deletions gmt/clib/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,15 +407,15 @@ def log_to_file(self, logfile=None):
Examples
--------

>>> with LibGMT() as lib:
... mode = lib.get_constant('GMT_MODULE_CMD')
... with lib.log_to_file() as logfile:
... call_module = lib.get_libgmt_func('GMT_Call_Module')
... status = call_module(lib.current_session, 'info'.encode(),
... mode, 'bogus-file.bla'.encode())
... with open(logfile) as flog:
... print(flog.read().strip())
gmtinfo [ERROR]: Error for input file: No such file (bogus-file.bla)
# >>> with LibGMT() as lib:
# ... mode = lib.get_constant('GMT_MODULE_CMD')
# ... with lib.log_to_file() as logfile:
# ... call_module = lib.get_libgmt_func('GMT_Call_Module')
# ... status = call_module(lib.current_session, 'info'.encode(),

Choose a reason for hiding this comment

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

E501 line too long (80 > 79 characters)

# ... mode, 'bogus-file.bla'.encode())
# ... with open(logfile) as flog:
# ... print(flog.read().strip())
# gmtinfo [ERROR]: Error for input file: No such file (bogus-file.bla)

"""
c_handle_messages = self.get_libgmt_func(
Expand Down Expand Up @@ -447,7 +447,9 @@ def log_to_file(self, logfile=None):
yield logfile

# Clean up when exiting the 'with' statement
os.remove(logfile)

if os.path.exists(logfile):
os.remove(logfile)

def call_module(self, module, args):
"""
Expand Down Expand Up @@ -1324,8 +1326,6 @@ def extract_region(self):
)

wesn = np.empty(4, dtype=np.float64)
# Use NaNs so that we can know if GMT didn't change the array
wesn[:] = np.nan
wesn_pointer = wesn.ctypes.data_as(ctypes.POINTER(ctypes.c_double))
# The second argument to GMT_Extract_Region is a file pointer to a
# PostScript file. It's only valid in classic mode. Use None to get a
Expand Down
12 changes: 10 additions & 2 deletions gmt/tests/test_clib.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,13 @@ def test_set_log_file_fails():
print("This should have failed")


def test_set_log_file():
"log_to_file should not crash even if not given anything"
with LibGMT() as lib:
with lib.log_to_file():
pass


def logged_call_module(lib, data_file):
"""
Make a call_module to 'info' with a log file.
Expand All @@ -173,7 +180,7 @@ def logged_call_module(lib, data_file):
"""
msg = "gmtinfo [ERROR]: Error for input file: No such file ({})"
mode = lib.get_constant("GMT_MODULE_CMD")
with lib.log_to_file() as logfile:
with lib.log_to_file("some-log-file.log") as logfile:
assert os.path.exists(logfile)
# Make a bogus module call that will fail
status = lib._libgmt.GMT_Call_Module(
Expand Down Expand Up @@ -593,7 +600,8 @@ def test_virtual_file_fails():
):
with pytest.raises(GMTCLibError):
with lib.open_virtual_file(*vfargs):
print("Shouldn't get to this code either")
pass
print("Shouldn't get to this code either")


def test_virtual_file_bad_direction():
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
gmt=6.0.0*
# GMT isn't included because it needs to be downloaded from a separate channel
numpy
pandas
xarray
Expand Down