Coverage for tests/test_dummy_sim.py: 41%

1 import datetime

2

3 from cgse_dummy.dummy_sim import _VERSION

4 from cgse_dummy.dummy_sim import send_command

5 from cgse_dummy.dummy_sim import send_request

6

7

8 def test_send_request():

9 response = send_request("*IDN?")

10

11 parts = response.decode().strip().split(", ")

12

13 assert len(parts) == 4

14

15 manufacturer, model, sn, version = parts

16 assert manufacturer == "DUMMY INSTRUMENTS" # check the settings.yaml if this test fails

17 assert model == "DAQ-1234" # check the settings.yaml if this test fails

18 assert sn == "SN2025-X23-5" # check the settings.yaml if this test fails

19 assert version == _VERSION

20

21 def test_info():

22 response = send_request("info").decode().strip()

23

24 assert "DUMMY INSTRUMENTS" in response

25 assert "0.0.2" in response

26

27 def test_get_value():

28 response = send_request("get_value").decode().strip()

29 value_1 = float(response)

30

31 assert -185.0 < value_1 < 30.0

32

33 response = send_request("get_value").decode().strip()

34 value_2 = float(response)

35

36 assert value_1 != value_2

37

38

39 def test_system_time():

40

41 send_command(":SYST:TIME 2025, 10, 10, 12, 12, 00")

42

43 response = send_request(":SYST:TIME?").decode().strip()

44 sys_time = datetime.datetime.strptime(response, "%a %b %d %H:%M:%S %Y")

45

46 # it shouldn't take 2s to execute this test!

47 assert sys_time <= datetime.datetime(2025, 10, 10, 12, 12, 2)