Coverage for tests/test_utilities.py: 100%

16 statements  

« prev     ^ index     » next       coverage.py v7.17.0, created at 2026-10-30 18:01 +0000

1"""Tests of crimepy's shared tools. 

2 

3Contents: 

4 test_another_data_folder_can_be_named: checks the other data folders. 

5 test_the_data_folder_is_in_the_workspace: checks the default data folder. 

6 

7""" 

8 

9from __future__ import annotations 

10 

11import pathlib 

12 

13import pytest 

14 

15from crimepy import options, utilities 

16 

17""" Tests """ 

18 

19 

20def test_the_data_folder_is_in_the_workspace(tmp_path: pathlib.Path) -> None: 

21 """Checks that the data folder is the "crime" folder of amos's workspace. 

22 

23 Args: 

24 tmp_path: the test's temporary folder, which is amos's workspace 

25 (see the "workspace" fixture). 

26 

27 """ 

28 folder = utilities.data_folder() 

29 assert folder == tmp_path / 'data' / 'crime' 

30 assert folder.is_dir() 

31 

32 

33def test_another_data_folder_can_be_named( 

34 tmp_path: pathlib.Path, 

35 monkeypatch: pytest.MonkeyPatch) -> None: 

36 """Checks that a folder argument and the options name other folders. 

37 

38 Args: 

39 tmp_path: the test's temporary folder. 

40 monkeypatch: sets the options for the test. 

41 

42 """ 

43 assert utilities.data_folder(tmp_path / 'given') == tmp_path / 'given' 

44 monkeypatch.setattr(options, 'DATA_FOLDER', tmp_path / 'chosen') 

45 assert utilities.data_folder() == tmp_path / 'chosen' 

46 monkeypatch.setattr(options, 'DATA_FOLDER', None) 

47 monkeypatch.setattr(options, 'DATA_SUBFOLDER', 'records') 

48 assert utilities.data_folder() == tmp_path / 'data' / 'records'