Coverage for pesummary/tests/action_test.py: 100.0%

46 statements  

« prev     ^ index     » next       coverage.py v7.4.4, created at 2024-05-02 08:42 +0000

1from pesummary.core.cli.actions import ConfigAction 

2 

3def test_dict_from_str(): 

4 f = ConfigAction.dict_from_str("{'H1':10, 'L1':20}") 

5 assert sorted(list(f.keys())) == ["H1", "L1"] 

6 assert f["H1"] == 10 

7 assert f["L1"] == 20 

8 f = ConfigAction.dict_from_str("{'H1':'/home/IFO0.dat', 'L1': '/home/IFO1.dat'}") 

9 assert f["H1"] == "/home/IFO0.dat" 

10 assert f["L1"] == "/home/IFO1.dat" 

11 f = ConfigAction.dict_from_str("{'H1'=10, 'L1'=20}") 

12 assert sorted(list(f.keys())) == ["H1", "L1"] 

13 assert f["H1"] == 10 

14 assert f["L1"] == 20 

15 f = ConfigAction.dict_from_str("{H1=10, L1=20}") 

16 assert sorted(list(f.keys())) == ["H1", "L1"] 

17 assert f["H1"] == 10 

18 assert f["L1"] == 20 

19 f = ConfigAction.dict_from_str("dict(H1=10, L1=20)") 

20 assert sorted(list(f.keys())) == ["H1", "L1"] 

21 assert f["H1"] == 10 

22 assert f["L1"] == 20 

23 f = ConfigAction.dict_from_str("{H1$10, L1$20}", delimiter="$") 

24 assert sorted(list(f.keys())) == ["H1", "L1"] 

25 assert f["H1"] == 10 

26 assert f["L1"] == 20 

27 f = ConfigAction.dict_from_str("{H1=10, L1=20}", dtype=str) 

28 assert sorted(list(f.keys())) == ["H1", "L1"] 

29 assert isinstance(f["H1"], str) 

30 assert isinstance(f["L1"], str) 

31 f = ConfigAction.dict_from_str("{H1=10, L1:20, V1=2}") 

32 assert f["H1"] == 10 

33 assert f["L1"] == 20 

34 assert f["V1"] == 2 

35 f = ConfigAction.dict_from_str("{}") 

36 assert not len(f) 

37 

38def test_list_from_str(): 

39 f = ConfigAction.list_from_str('[1,2,3]', dtype=int) 

40 assert f == [1,2,3] 

41 f = ConfigAction.list_from_str('[1, 2, 3]', dtype=int) 

42 assert f == [1,2,3] 

43 f = ConfigAction.list_from_str('1, 2, 3', dtype=int) 

44 assert f == [1,2,3] 

45 f = ConfigAction.list_from_str("[/home/IFO0.dat, /home/IFO1.dat]") 

46 assert f == ["/home/IFO0.dat", "/home/IFO1.dat"] 

47 f = ConfigAction.list_from_str("['/home/IFO0.dat', '/home/IFO1.dat']") 

48 assert f == ["/home/IFO0.dat", "/home/IFO1.dat"]