|
| 1 | +# Copyright (c) 2017-2018 Uber Technologies, Inc. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | +import os |
| 15 | + |
| 16 | +import pytest |
| 17 | + |
| 18 | +from petastorm import make_reader |
| 19 | + |
| 20 | + |
| 21 | +def dataset_urls(): |
| 22 | + """Returns a list of legacy datasets available for testing""" |
| 23 | + legacy_data_directory = os.path.join(os.path.dirname(__file__), 'data', 'legacy') |
| 24 | + versions = os.listdir(legacy_data_directory) |
| 25 | + urls = ['file://' + os.path.join(legacy_data_directory, v) for v in versions] |
| 26 | + return urls |
| 27 | + |
| 28 | + |
| 29 | +@pytest.mark.parametrize('legacy_dataset_url', dataset_urls()) |
| 30 | +def test_reading_legacy_dataset(legacy_dataset_url): |
| 31 | + """The test runs for a single legacy dataset. Opens the dataset using `make_reader` and reads all records from it""" |
| 32 | + with make_reader(legacy_dataset_url, workers_count=1) as reader: |
| 33 | + all_data = list(reader) |
| 34 | + |
| 35 | + # Some basic check on the data |
| 36 | + assert len(all_data) == 100 |
| 37 | + assert len(all_data[0]._fields) > 5 |
| 38 | + assert all_data[0].matrix.shape == (32, 16, 3) |
0 commit comments