Skip to content

Commit cd07813

Browse files
authored
CI: flaky zip test (#40417)
1 parent 015c0c0 commit cd07813

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

pandas/tests/io/test_gcs.py

+16-6
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,17 @@ def test_to_read_gcs(gcs_buffer, format):
9797
tm.assert_frame_equal(df1, df2)
9898

9999

100+
def assert_equal_zip_safe(result: bytes, expected: bytes):
101+
"""
102+
We would like to assert these are equal, but the 11th byte is a last-modified
103+
timestamp, which in some builds is off-by-one, so we check around that.
104+
105+
See https://en.wikipedia.org/wiki/ZIP_(file_format)#File_headers
106+
"""
107+
assert result[:10] == expected[:10]
108+
assert result[11:] == expected[11:]
109+
110+
100111
@td.skip_if_no("gcsfs")
101112
@pytest.mark.parametrize("encoding", ["utf-8", "cp1251"])
102113
def test_to_csv_compression_encoding_gcs(gcs_buffer, compression_only, encoding):
@@ -121,7 +132,10 @@ def test_to_csv_compression_encoding_gcs(gcs_buffer, compression_only, encoding)
121132
# write compressed file with explicit compression
122133
path_gcs = "gs://test/test.csv"
123134
df.to_csv(path_gcs, compression=compression, encoding=encoding)
124-
assert gcs_buffer.getvalue() == buffer.getvalue()
135+
res = gcs_buffer.getvalue()
136+
expected = buffer.getvalue()
137+
assert_equal_zip_safe(res, expected)
138+
125139
read_df = read_csv(
126140
path_gcs, index_col=0, compression=compression_only, encoding=encoding
127141
)
@@ -136,11 +150,7 @@ def test_to_csv_compression_encoding_gcs(gcs_buffer, compression_only, encoding)
136150

137151
res = gcs_buffer.getvalue()
138152
expected = buffer.getvalue()
139-
# We would like to assert these are equal, but the 11th byte is a last-modified
140-
# timestamp, which in some builds is off-by-one, so we check around that
141-
# See https://en.wikipedia.org/wiki/ZIP_(file_format)#File_headers
142-
assert res[:10] == expected[:10]
143-
assert res[11:] == expected[11:]
153+
assert_equal_zip_safe(res, expected)
144154

145155
read_df = read_csv(path_gcs, index_col=0, compression="infer", encoding=encoding)
146156
tm.assert_frame_equal(df, read_df)

0 commit comments

Comments
 (0)