Skip to content

Commit

Permalink
Adding has_group and has_channel (#314)
Browse files Browse the repository at this point in the history
  • Loading branch information
looopTools authored Nov 5, 2023
1 parent ea567c8 commit 58b9808
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
14 changes: 14 additions & 0 deletions nptdms/tdms.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,13 @@ def __len__(self):
"""
return len(self._groups)

def __contains__(self, group_name):
""" Check if TDMS file contains groupp
:rtype: Boolean
"""
return group_name in self._groups

def __iter__(self):
""" Returns an iterator over the names of groups in this file
"""
Expand Down Expand Up @@ -355,6 +362,13 @@ def __init__(self, path, properties, channels):
def __repr__(self):
return "<TdmsGroup with path %s>" % self.path

def __contains__(self, channel_name):
""" Check if group contains channel
:rtype: Boolean
"""
return channel_name in self._channels

@property
def path(self):
""" Path to the TDMS object for this group
Expand Down
22 changes: 22 additions & 0 deletions nptdms/test/test_tdms_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,28 @@ def test_object_repr():
assert repr(channel) == "<TdmsChannel with path /'Group'/'Channel1'>"


def test_group_in_tdms_object():
"""Test in for TDMS object
"""
test_file = GeneratedFile()
test_file.add_segment(*basic_segment())
tdms_data = test_file.load()

assert 'Group' in tdms_data
assert 'group' not in tdms_data


def test_channel_in_group_object():
"""Test in for group
"""
test_file = GeneratedFile()
test_file.add_segment(*basic_segment())
tdms_data = test_file.load()

assert 'Channel1' in tdms_data['Group']
assert 'channel1' not in tdms_data['Group']


def test_data_read_from_bytes_io():
"""Test reading data"""

Expand Down

0 comments on commit 58b9808

Please sign in to comment.