Skip to content

Commit

Permalink
Resurrecting test_reading_legacy_dataset test
Browse files Browse the repository at this point in the history
It was removed by mistake. The test actually tests an ability to read a
dataset created with previous version of petastorm.
  • Loading branch information
Yevgeni Litvin committed Apr 14, 2022
1 parent 6dae6be commit 513533b
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
2 changes: 2 additions & 0 deletions petastorm/etl/safe_pickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
"pyspark",
"decimal",
"builtins",
"copy_reg",
"__builtin__",
}


Expand Down
38 changes: 38 additions & 0 deletions petastorm/tests/test_reading_legacy_datasets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Copyright (c) 2017-2018 Uber Technologies, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import os

import pytest

from petastorm import make_reader


def dataset_urls():
"""Returns a list of legacy datasets available for testing"""
legacy_data_directory = os.path.join(os.path.dirname(__file__), 'data', 'legacy')
versions = os.listdir(legacy_data_directory)
urls = ['file://' + os.path.join(legacy_data_directory, v) for v in versions]
return urls


@pytest.mark.parametrize('legacy_dataset_url', dataset_urls())
def test_reading_legacy_dataset(legacy_dataset_url):
"""The test runs for a single legacy dataset. Opens the dataset using `make_reader` and reads all records from it"""
with make_reader(legacy_dataset_url, workers_count=1) as reader:
all_data = list(reader)

# Some basic check on the data
assert len(all_data) == 100
assert len(all_data[0]._fields) > 5
assert all_data[0].matrix.shape == (32, 16, 3)

0 comments on commit 513533b

Please sign in to comment.