Coverage for hiperta_stream/scripts/tests/test_scripts.py: 95%

20 statements  

« prev     ^ index     » next       coverage.py v7.4.3, created at 2024-07-16 10:16 +0000

1# Most of the tests based on 

2# https://github.com/cta-observatory/cta-lstchain/blob/master/lstchain/scripts/tests/test_lstchain_scripts.py 

3 

4import pytest 

5import subprocess 

6import pkg_resources 

7 

8 

9def find_entry_points(package_name): 

10 """from: https://stackoverflow.com/a/47383763/3838691""" 

11 entrypoints = [ 

12 ep.name 

13 for ep in pkg_resources.iter_entry_points("console_scripts") 

14 if ep.module_name.startswith(package_name) 

15 ] 

16 return entrypoints 

17 

18 

19ALL_SCRIPTS = find_entry_points("hiperta") + find_entry_points("rta") 

20 

21 

22def run_script(*args): 

23 result = subprocess.run(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, encoding='utf-8') 

24 

25 if result.returncode != 0: 

26 raise ValueError( 

27 f"Running {args[0]} failed with return code {result.returncode}" 

28 f", output: \n {result.stdout}" 

29 ) 

30 

31 

32@pytest.mark.parametrize("script", ALL_SCRIPTS) 

33def test_all_help(script): 

34 """Test for all scripts if at least the help works.""" 

35 run_script(script, "--help") 

36 

37 

38def test_run_sync_monitoring(): 

39 run_script("which", "sync_monitoring.sh") 

40 

41 

42def test_script_get_offset(): 

43 run_script("which", "script_get_offset_stream.sh") 

44 

45 

46def test_script_record_lst_stream(): 

47 run_script("which", "script_record_lst_stream.sh")