Coverage for tests / test_findPackageFile.py: 11%

27 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-05-06 08:41 +0000

1import pytest 

2 

3from lsst.ctrl.execute.findPackageFile import find_package_file 

4 

5 

6def test_find_package_file(tmp_path, monkeypatch): 

7 mock_home = tmp_path / "home" / "pytest" 

8 (mock_home / ".lsst").mkdir(parents=True) 

9 (mock_home / ".lsst" / "opt").mkdir(parents=True) 

10 (mock_home / ".config" / "lsst").mkdir(parents=True) 

11 

12 mock_lsst_file = mock_home / ".lsst" / "test_file_1.py" 

13 mock_rel_file = mock_home / ".lsst" / "opt" / "test_file_3.py" 

14 mock_xdg_file = mock_home / ".config" / "lsst" / "test_file_2.py" 

15 

16 mock_lsst_file.touch() 

17 mock_rel_file.touch() 

18 mock_xdg_file.touch() 

19 

20 monkeypatch.setenv("HOME", str(mock_home)) 

21 monkeypatch.setenv("XDG_CONFIG_HOME", str(mock_home / ".config")) 

22 monkeypatch.setenv("PREFIX", "opt") 

23 

24 f1 = find_package_file("test_file_1.py") 

25 f2 = find_package_file("test_file_2.py") 

26 f3 = find_package_file("$PREFIX/test_file_3.py") 

27 f4 = find_package_file("$HOME/test_file_4.py") 

28 

29 # f1 should be found in the `~/.lsst` directory 

30 assert "home/pytest/.lsst" in str(f1) 

31 

32 # f2 should be found in the `~/.config/lsst` directory 

33 assert "home/pytest/.config/lsst" in str(f2) 

34 

35 # f3 should be found at a relative path 

36 assert "home/pytest/.lsst/opt/" in str(f3) 

37 

38 # f4 should be a straight absolute path, which means it has not been 

39 # checked for existence 

40 assert not f4.exists() 

41 assert "/home/pytest/test_file_4.py" in str(f4) 

42 

43 # f5 should not be found at all 

44 with pytest.raises(FileNotFoundError): 

45 _ = find_package_file("test_file_5.py")