/
test_dataset.py
62 lines (47 loc) · 2.04 KB
/
test_dataset.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# -*- coding: utf-8 -*-
#
# Copyright 2017-2021 - Swiss Data Science Center (SDSC)
# A partnership between École Polytechnique Fédérale de Lausanne (EPFL) and
# Eidgenössische Technische Hochschule Zürich (ETHZ).
#
# 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.
"""Tests for Dataset API."""
import os
import pytest
from renku.api import Dataset, Project
def test_list_datasets(client_with_datasets):
"""Test listing datasets within a project context."""
with Project():
datasets = Dataset.list()
assert {"dataset-1", "dataset-2"} == {d.name for d in datasets}
def test_list_datasets_outside_a_context(client_with_datasets):
"""Test listing datasets outside a project context."""
datasets = Dataset.list()
assert {"dataset-1", "dataset-2"} == {d.name for d in datasets}
def test_list_datasets_outside_a_renku_project(directory_tree):
"""Test listing datasets in a non-renku directory."""
os.chdir(directory_tree)
assert [] == Dataset.list()
@pytest.mark.parametrize(
"dataset, files_paths",
[
("dataset-1", []),
("dataset-2", ["data/dataset-2/file1", "data/dataset-2/dir1/file2", "data/dataset-2/dir1/file3"]),
],
)
def test_list_dataset_files(client_with_datasets, dataset, files_paths):
"""Test listing datasets files."""
with Project() as project:
dataset = next(d for d in Dataset.list() if d.name == dataset)
assert set(files_paths) == {f.path for f in dataset.files}
assert set(project.path / p for p in files_paths) == {d.full_path for d in dataset.files}