Skip to content

Commit

Permalink
Add channel length to tdmsinfo output and improve test coverage (#175)
Browse files Browse the repository at this point in the history
* Add channel length to tdmsinfo output and improve test coverage
* Test debug output in tdmsinfo
  • Loading branch information
adamreeve committed Mar 31, 2020
1 parent 06bec71 commit a12356c
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 16 deletions.
21 changes: 11 additions & 10 deletions docs/tdmsinfo.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,23 @@ Usage looks like::
tdmsinfo [--properties] tdms_file

Passing the ``--properties`` or ``-p`` argument will include TDMS object
properties in the printed information.
properties in the printed information as well as the data type and length of channels.

The output of tdmsinfo including properties will look something like::

/
properties:
name: test_file
/'group_1'
properties:
group_property: property value
/'group_1'/'channel_a'
data type: tdsTypeU8
name: test_file
/'group_1'
properties:
group_property: property value
/'group_1'/'channel_1'
data type: Uint32
length: 2000
properties:
wf_start_time: 2016-12-3014:56:00+00:00
wf_increment: 0.0005
wf_samples: 2000
wf_start_time: 2016-12-3014:56:00+00:00
wf_increment: 0.0005
wf_samples: 200

There is also a ``--debug`` or ``-d`` argument that will output debug information
to stderr, which can be useful when debugging a problem with a TDMS file.
1 change: 1 addition & 0 deletions nptdms/tdmsinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def tdmsinfo(file, show_properties=False):
level = 3
if channel.data_type is not None:
display("data type: %s" % channel.data_type.__name__, level)
display("length: %d" % len(channel), level)
display_properties(channel, level)


Expand Down
37 changes: 32 additions & 5 deletions nptdms/test/test_tdmsinfo.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,52 @@
import os
from nptdms.tdmsinfo import tdmsinfo
import sys
from nptdms import tdmsinfo
from nptdms.test.util import GeneratedFile, basic_segment
try:
from unittest.mock import patch
except ImportError:
from mock import patch


def test_tdmsinfo():
def test_tdmsinfo(capsys):
test_file = GeneratedFile()
test_file.add_segment(*basic_segment())
temp_file = test_file.get_tempfile(delete=False)
try:
temp_file.file.close()
tdmsinfo(temp_file.name)
with patch.object(sys, 'argv', ['tdmsinfo.py', temp_file.name]):
tdmsinfo.main()
captured = capsys.readouterr()
assert "/'Group'/'Channel1'" in captured.out
assert "wf_start_offset" not in captured.out
finally:
os.remove(temp_file.name)


def test_tdmsinfo_with_properties():
def test_tdmsinfo_with_properties(capsys):
test_file = GeneratedFile()
test_file.add_segment(*basic_segment())
temp_file = test_file.get_tempfile(delete=False)
try:
temp_file.file.close()
tdmsinfo(temp_file.name, show_properties=True)
with patch.object(sys, 'argv', ['tdmsinfo.py', temp_file.name, '--properties']):
tdmsinfo.main()
captured = capsys.readouterr()
assert "/'Group'/'Channel1'" in captured.out
assert "wf_start_offset: 0.0" in captured.out
assert "length: 2" in captured.out
finally:
os.remove(temp_file.name)


def test_tdmsinfo_with_debug_output(caplog):
test_file = GeneratedFile()
test_file.add_segment(*basic_segment())
temp_file = test_file.get_tempfile(delete=False)
try:
temp_file.file.close()
with patch.object(sys, 'argv', ['tdmsinfo.py', temp_file.name, '--debug']):
tdmsinfo.main()
assert "Reading metadata for object /'Group'/'Channel1'" in caplog.text
finally:
os.remove(temp_file.name)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def read_version():
],
install_requires = ['numpy'],
extras_require = {
'test': ['pytest>=3.1.0', 'hypothesis'],
'test': ['pytest>=3.1.0', 'hypothesis', 'mock<4.0;python_version<"3.4"'],
'pandas': ['pandas'],
'hdf': ['h5py>=2.10.0'],
'thermocouple_scaling': ['thermocouples_reference', 'scipy'],
Expand Down

0 comments on commit a12356c

Please sign in to comment.