11from __future__ import annotations
22
3- import pathlib
43from unittest import mock
54
6- import py
7- import pytest
8-
95import dials_data
106import dials_data .datasets
117import dials_data .download
@@ -22,60 +18,12 @@ def test_repository_location():
2218
2319def test_fetching_undefined_datasets_does_not_crash ():
2420 df = dials_data .download .DataFetcher (read_only = True )
25- assert df ("aardvark" , pathlib = True ) is False
21+ assert df ("aardvark" ) is False
2622
2723
2824def test_requests_for_future_datasets_can_be_intercepted ():
2925 df = dials_data .download .DataFetcher (read_only = True )
3026 df .result_filter = mock .Mock ()
3127 df .result_filter .return_value = False
32- assert df ("aardvark" , pathlib = True ) is False
28+ assert df ("aardvark" ) is False
3329 df .result_filter .assert_called_once_with (result = False )
34-
35-
36- @mock .patch ("dials_data.datasets.repository_location" )
37- @mock .patch ("dials_data.download.fetch_dataset" )
38- def test_datafetcher_constructs_py_path (fetcher , root ):
39- root .return_value = pathlib .Path ("/tmp/root" )
40- fetcher .return_value = True
41-
42- df = dials_data .download .DataFetcher (read_only = True )
43- with pytest .warns (DeprecationWarning ):
44- ds = df ("dataset" )
45- assert pathlib .Path (ds ).resolve () == pathlib .Path ("/tmp/root/dataset" ).resolve ()
46- assert isinstance (ds , py .path .local )
47- fetcher .assert_called_once_with (
48- "dataset" , pre_scan = True , read_only = False , verify = True
49- )
50-
51- ds = df ("dataset" , pathlib = False )
52- assert pathlib .Path (ds ).resolve () == pathlib .Path ("/tmp/root/dataset" ).resolve ()
53- assert isinstance (ds , py .path .local )
54- fetcher .assert_called_once ()
55-
56-
57- @mock .patch ("dials_data.datasets.repository_location" )
58- @mock .patch ("dials_data.download.fetch_dataset" )
59- def test_datafetcher_constructs_path (fetcher , root ):
60- test_path = pathlib .Path ("/tmp/root" )
61- root .return_value = test_path
62- fetcher .return_value = True
63-
64- df = dials_data .download .DataFetcher (read_only = True )
65- ds = df ("dataset" , pathlib = True )
66- assert ds == test_path / "dataset"
67-
68- assert isinstance (ds , pathlib .Path )
69- fetcher .assert_called_once_with (
70- "dataset" , pre_scan = True , read_only = False , verify = True
71- )
72-
73- with pytest .warns (DeprecationWarning ):
74- ds = df ("dataset" )
75- assert pathlib .Path (ds ).resolve () == test_path .joinpath ("dataset" ).resolve ()
76- assert not isinstance (
77- ds , pathlib .Path
78- ) # default is currently to return py.path.local()
79- fetcher .assert_called_once_with (
80- "dataset" , pre_scan = True , read_only = False , verify = True
81- )
0 commit comments