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

explicitly clear linecache cache once parsing is finished #60

Merged
merged 1 commit into from
May 21, 2024
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
2 changes: 2 additions & 0 deletions src/starfile/parser.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import linecache
from collections import deque
from io import StringIO
from linecache import getline
Expand Down Expand Up @@ -45,6 +46,7 @@ def __init__(
# parse file
self.current_line_number = 0
self.parse_file()
linecache.clearcache()

@property
def current_line(self) -> str:
Expand Down
18 changes: 17 additions & 1 deletion tests/test_read_write_round_trip.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import time

import pandas.testing

from .constants import two_single_line_loop_blocks, postprocess

import starfile
Expand Down Expand Up @@ -35,4 +39,16 @@ def test_round_trip_postprocess(tmp_path):
if isinstance(_actual, pd.DataFrame):
pd.testing.assert_frame_equal(_actual, _expected, atol=1e-6)
else:
assert _actual == _expected
assert _actual == _expected


def test_write_read_write_read():
filename = 'tmp.star'
df_a = pd.DataFrame({'a': [0, 1], 'b': [2, 3]})
starfile.write(df_a, filename)

df_b = pd.DataFrame({'c': [0, 1], 'd': [2, 3]})
starfile.write(df_b, filename)

df_b_read = starfile.read(filename)
pandas.testing.assert_frame_equal(df_b, df_b_read)
Loading