Skip to content
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

Adding has_group and has_channel #314

Merged
merged 5 commits into from
Nov 5, 2023
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
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
Loading