Skip to content

Commit

Permalink
Fix defragmenting a file with timestamp channel data
Browse files Browse the repository at this point in the history
  • Loading branch information
adamreeve committed Jan 25, 2024
1 parent 7da3c7e commit 9369440
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
13 changes: 13 additions & 0 deletions nptdms/test/writer/test_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import tempfile

from nptdms import TdmsFile, TdmsWriter, RootObject, GroupObject, ChannelObject, types
from nptdms.test import scenarios


def test_can_read_tdms_file_after_writing():
Expand Down Expand Up @@ -550,3 +551,15 @@ def test_write_and_store_index_file():
])

assert os.path.isfile(tdms_path + "_index")


def test_defragment_raw_timestamp_file():
test_file, expected_data = scenarios.timestamp_data().values
with test_file.get_tempfile() as temp_file:
target_buf = BytesIO()
TdmsWriter.defragment(temp_file, target_buf)
target_buf.seek(0, os.SEEK_SET)
f = TdmsFile.read(target_buf)
for (group, channel), expected_values in expected_data.items():
channel_data = f[group][channel][:]
np.testing.assert_equal(channel_data, expected_values)
3 changes: 3 additions & 0 deletions nptdms/timestamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ class TdmsTimestamp(object):
:ivar ~.seconds: Seconds since the epoch as a signed integer
:ivar ~.second_fractions: A positive number of 2^-64 fractions of a second
"""

# Attributes that let this class act like a TdmsType when writing data
enum_value = 0x44
size = 16

def __init__(self, seconds, second_fractions):
self.seconds = seconds
Expand Down

0 comments on commit 9369440

Please sign in to comment.