Skip to content

Add docstrings and tests to gmtinfo #144

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

Merged
merged 8 commits into from
Mar 14, 2018
Merged
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
20 changes: 20 additions & 0 deletions gmt/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,32 @@ def info(fname, **kwargs):
"""
Get information about data tables.

Reads from files and finds the extreme values in each of the columns.
It recognizes NaNs and will print warnings if the number of columns vary
from record to record. As an option, it will find the extent of the first
n columns rounded up and down to the nearest multiple of the supplied
increments. By default, this output will be in the form *-Rw/e/s/n*,
or the output will be in column form for as many columns as there are
increments provided. The *T* option will provide a *-Tzmin/zmax/dz* string
for makecpt.

{gmt_module_docs}

Parameters
----------
fname : str
The file name of the input data table file.
C : bool
Report the min/max values per column in separate columns.
I : str
``'[b|p|f|s]dx[/dy[/dz...]]'``.
Report the min/max of the first n columns to the nearest multiple of
the provided increments and output results in the form *-Rw/e/s/n*
(unless *C* is set).
T : str
``'dz[+ccol]'``
Report the min/max of the first (0'th) column to the nearest multiple
of dz and output this as the string *-Tzmin/zmax/dz*.
"""
assert isinstance(fname, str), 'Only accepts file names.'

Expand Down
15 changes: 0 additions & 15 deletions gmt/tests/test_gmtinfo.py

This file was deleted.

44 changes: 44 additions & 0 deletions gmt/tests/test_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"""
Tests for gmtinfo
"""
import os

from .. import info

TEST_DATA_DIR = os.path.join(os.path.dirname(__file__), 'data')
POINTS_DATA = os.path.join(TEST_DATA_DIR, 'points.txt')


def test_info():
"Make sure info works"
output = info(fname=POINTS_DATA)
expected_output = ('{}: N = 20 '
'<11.5309/61.7074> '
'<-2.9289/7.8648> '
'<0.1412/0.9338>\n').format(POINTS_DATA)

assert output == expected_output


def test_info_c():
"Make sure the C option works"
output = info(fname=POINTS_DATA, C=True)
assert output == '11.5309 61.7074 -2.9289 7.8648 0.1412 0.9338\n'


def test_info_i():
"Make sure the I option works"
output = info(fname=POINTS_DATA, I=0.1)
assert output == '-R11.5/61.8/-3/7.9\n'


def test_info_c_i():
"Make sure the C and I options work together"
output = info(fname=POINTS_DATA, C=True, I=0.1)
assert output == '11.5 61.8 -3 7.9 0.1412 0.9338\n'


def test_info_t():
"Make sure the T option works"
output = info(fname=POINTS_DATA, T=0.1)
assert output == '-T11.5/61.8/0.1\n'