shepherd-core 2023.10.3__py3-none-any.whl → 2023.12.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. shepherd_core/__init__.py +1 -1
  2. shepherd_core/data_models/base/content.py +3 -8
  3. shepherd_core/data_models/base/shepherd.py +2 -6
  4. shepherd_core/data_models/content/virtual_source.py +13 -40
  5. shepherd_core/data_models/experiment/experiment.py +3 -8
  6. shepherd_core/data_models/experiment/observer_features.py +4 -9
  7. shepherd_core/data_models/experiment/target_config.py +4 -11
  8. shepherd_core/data_models/task/__init__.py +2 -6
  9. shepherd_core/data_models/task/emulation.py +7 -14
  10. shepherd_core/data_models/task/firmware_mod.py +1 -3
  11. shepherd_core/data_models/task/harvest.py +1 -3
  12. shepherd_core/data_models/testbed/cape_fixture.yaml +2 -1
  13. shepherd_core/data_models/testbed/observer.py +6 -22
  14. shepherd_core/data_models/testbed/observer_fixture.yaml +46 -16
  15. shepherd_core/data_models/testbed/target_fixture.yaml +18 -16
  16. shepherd_core/data_models/testbed/testbed.py +1 -3
  17. shepherd_core/data_models/testbed/testbed_fixture.yaml +2 -0
  18. shepherd_core/decoder_waveform/uart.py +8 -26
  19. shepherd_core/fw_tools/__init__.py +1 -3
  20. shepherd_core/fw_tools/converter.py +4 -12
  21. shepherd_core/fw_tools/patcher.py +4 -12
  22. shepherd_core/fw_tools/validation.py +2 -2
  23. shepherd_core/inventory/__init__.py +3 -9
  24. shepherd_core/inventory/python.py +7 -5
  25. shepherd_core/inventory/system.py +2 -5
  26. shepherd_core/logger.py +1 -3
  27. shepherd_core/reader.py +45 -41
  28. shepherd_core/testbed_client/client.py +5 -16
  29. shepherd_core/testbed_client/fixtures.py +4 -8
  30. shepherd_core/testbed_client/user_model.py +1 -3
  31. shepherd_core/vsource/virtual_converter_model.py +4 -14
  32. shepherd_core/vsource/virtual_harvester_model.py +1 -3
  33. shepherd_core/vsource/virtual_source_model.py +2 -6
  34. shepherd_core/writer.py +11 -22
  35. {shepherd_core-2023.10.3.dist-info → shepherd_core-2023.12.1.dist-info}/METADATA +16 -5
  36. {shepherd_core-2023.10.3.dist-info → shepherd_core-2023.12.1.dist-info}/RECORD +53 -53
  37. {shepherd_core-2023.10.3.dist-info → shepherd_core-2023.12.1.dist-info}/WHEEL +1 -1
  38. tests/conftest.py +32 -0
  39. tests/data_models/test_content_models.py +15 -9
  40. tests/data_models/test_experiment_models.py +2 -4
  41. tests/data_models/test_task_generation.py +1 -1
  42. tests/fw_tools/test_converter.py +11 -0
  43. tests/fw_tools/test_patcher.py +11 -4
  44. tests/fw_tools/test_validation.py +8 -0
  45. tests/inventory/test_inventory.py +1 -3
  46. tests/test_cal_hw.py +2 -6
  47. tests/test_examples.py +13 -2
  48. tests/test_writer.py +2 -2
  49. tests/vsource/conftest.py +1 -3
  50. tests/vsource/test_converter.py +2 -6
  51. tests/vsource/test_harvester.py +3 -9
  52. {shepherd_core-2023.10.3.dist-info → shepherd_core-2023.12.1.dist-info}/top_level.txt +0 -0
  53. {shepherd_core-2023.10.3.dist-info → shepherd_core-2023.12.1.dist-info}/zip-safe +0 -0
@@ -8,21 +8,24 @@ from shepherd_core import fw_tools
8
8
  from .conftest import files_elf
9
9
 
10
10
 
11
+ @pytest.mark.elf
11
12
  @pytest.mark.parametrize("path_elf", files_elf)
12
13
  def test_sym_finding(path_elf: Path) -> None:
13
14
  assert fw_tools.find_symbol(path_elf, "SHEPHERD_NODE_ID")
14
15
 
15
16
 
17
+ @pytest.mark.elf
16
18
  @pytest.mark.parametrize("path_elf", files_elf)
17
19
  def test_sym_reading(path_elf: Path) -> None:
18
20
  assert fw_tools.read_symbol(path_elf, "SHEPHERD_NODE_ID")
19
21
 
20
22
 
23
+ @pytest.mark.elf
21
24
  @pytest.mark.parametrize("path_elf", files_elf)
22
25
  def test_sym_mod(path_elf: Path, tmp_path: Path) -> None:
23
26
  value = 0xCAFE
24
27
  sym = "SHEPHERD_NODE_ID"
25
- path_new = tmp_path.with_name(path_elf.name).resolve()
28
+ path_new = tmp_path / path_elf.name
26
29
  shutil.copy(path_elf, path_new)
27
30
  path_gen = fw_tools.modify_symbol_value(path_new, sym, value, overwrite=False)
28
31
  assert path_gen.is_file()
@@ -33,13 +36,16 @@ def test_sym_mod(path_elf: Path, tmp_path: Path) -> None:
33
36
  assert value_new != value_old
34
37
 
35
38
 
39
+ @pytest.mark.elf
36
40
  @pytest.mark.parametrize("path_elf", files_elf)
37
41
  def test_sym_mod_overwrite(path_elf: Path, tmp_path: Path) -> None:
38
42
  value = 0xCAFE
39
43
  sym = "SHEPHERD_NODE_ID"
40
- path_new = tmp_path.with_name(path_elf.name).resolve()
44
+ path_new = tmp_path / path_elf.name
41
45
  shutil.copy(path_elf, path_new)
42
- path_gen = fw_tools.modify_symbol_value(path_new, sym, value, overwrite=True)
46
+ path_gen = fw_tools.modify_symbol_value(
47
+ path_new, sym, value, overwrite=True
48
+ ) # TODO: WinOS-trouble
43
49
  assert path_gen.is_file()
44
50
  assert path_gen.as_posix() == path_new.as_posix()
45
51
  value_new = fw_tools.read_symbol(path_gen, sym)
@@ -48,10 +54,11 @@ def test_sym_mod_overwrite(path_elf: Path, tmp_path: Path) -> None:
48
54
  assert value_new != value_old
49
55
 
50
56
 
57
+ @pytest.mark.elf
51
58
  @pytest.mark.parametrize("path_elf", files_elf)
52
59
  def test_id_mod(path_elf: Path, tmp_path: Path) -> None:
53
60
  value = 0xCAFE
54
- path_new = tmp_path.with_name(path_elf.name).resolve()
61
+ path_new = tmp_path / path_elf.name
55
62
  shutil.copy(path_elf, path_new)
56
63
  path_gen = fw_tools.modify_uid(path_new, value)
57
64
  assert path_gen.as_posix() == path_new.as_posix()
@@ -8,6 +8,8 @@ from shepherd_core.data_models import FirmwareDType
8
8
  from .conftest import files_elf
9
9
 
10
10
 
11
+ @pytest.mark.elf
12
+ @pytest.mark.converter
11
13
  @pytest.mark.parametrize("path_elf", files_elf)
12
14
  def test_elf_detection(path_elf: Path) -> None:
13
15
  assert fw_tools.is_elf(path_elf)
@@ -17,6 +19,8 @@ def test_elf_detection(path_elf: Path) -> None:
17
19
  assert fw_tools.is_elf_msp430(path_elf)
18
20
 
19
21
 
22
+ @pytest.mark.elf
23
+ @pytest.mark.converter
20
24
  @pytest.mark.parametrize("path_elf", files_elf)
21
25
  def test_elf_determination(path_elf: Path) -> None:
22
26
  assert fw_tools.determine_type(path_elf) == FirmwareDType.path_elf
@@ -26,6 +30,8 @@ def test_elf_determination(path_elf: Path) -> None:
26
30
  assert fw_tools.determine_arch(path_elf) == "msp430"
27
31
 
28
32
 
33
+ @pytest.mark.elf
34
+ @pytest.mark.converter
29
35
  @pytest.mark.parametrize("path_elf", files_elf)
30
36
  def test_hex_detection(path_elf: Path, tmp_path: Path) -> None:
31
37
  path_hex = (tmp_path / (path_elf.stem + ".hex")).resolve()
@@ -37,6 +43,8 @@ def test_hex_detection(path_elf: Path, tmp_path: Path) -> None:
37
43
  assert fw_tools.is_hex_msp430(path_hex)
38
44
 
39
45
 
46
+ @pytest.mark.elf
47
+ @pytest.mark.converter
40
48
  @pytest.mark.parametrize("path_elf", files_elf)
41
49
  def test_hex_determination(path_elf: Path, tmp_path: Path) -> None:
42
50
  path_hex = (tmp_path / (path_elf.stem + ".hex")).resolve()
@@ -9,9 +9,7 @@ from shepherd_core.inventory import SystemInventory
9
9
  from shepherd_core.inventory import TargetInventory
10
10
 
11
11
 
12
- @pytest.mark.parametrize(
13
- "inv", [PythonInventory, SystemInventory, TargetInventory, Inventory]
14
- )
12
+ @pytest.mark.parametrize("inv", [PythonInventory, SystemInventory, TargetInventory, Inventory])
15
13
  def test_collect_data(inv: Inventory) -> None:
16
14
  inv.collect()
17
15
 
tests/test_cal_hw.py CHANGED
@@ -10,9 +10,7 @@ from shepherd_core.calibration_hw_def import dac_raw_to_voltage
10
10
  from shepherd_core.calibration_hw_def import dac_voltage_to_raw
11
11
 
12
12
 
13
- @pytest.mark.parametrize(
14
- "fn", [adc_current_to_raw, adc_voltage_to_raw, dac_voltage_to_raw]
15
- )
13
+ @pytest.mark.parametrize("fn", [adc_current_to_raw, adc_voltage_to_raw, dac_voltage_to_raw])
16
14
  def test_convert_to_raw(fn: Callable) -> None:
17
15
  values = [-1, -1e-6, 1e-6, 1e-5, 1e-4, 1e-3, 1e-2, 1e-1, 1e-0]
18
16
  value_prev = -1
@@ -24,9 +22,7 @@ def test_convert_to_raw(fn: Callable) -> None:
24
22
  value_prev = value_raw
25
23
 
26
24
 
27
- @pytest.mark.parametrize(
28
- "fn", [adc_raw_to_current, adc_raw_to_voltage, dac_raw_to_voltage]
29
- )
25
+ @pytest.mark.parametrize("fn", [adc_raw_to_current, adc_raw_to_voltage, dac_raw_to_voltage])
30
26
  def test_convert_to_si(fn: Callable) -> None:
31
27
  values = [-100, -1, 0, 1, 2**6, 2**12, 2**18, 2**24]
32
28
  value_prev = -1
tests/test_examples.py CHANGED
@@ -15,8 +15,6 @@ def example_path() -> Path:
15
15
  examples = [
16
16
  "experiment_generic_var1.py",
17
17
  "experiment_models.py",
18
- "firmware_model.py",
19
- "firmware_modification.py",
20
18
  "inventory.py",
21
19
  "uart_decode_waveform.py",
22
20
  "vharvester_simulation.py",
@@ -27,3 +25,16 @@ examples = [
27
25
  @pytest.mark.parametrize("file", examples)
28
26
  def test_example_scripts(example_path: Path, file: str) -> None:
29
27
  subprocess.check_call(f"python {example_path / file}", shell=True)
28
+
29
+
30
+ examples_fw = [
31
+ "firmware_model.py",
32
+ "firmware_modification.py",
33
+ ]
34
+
35
+
36
+ @pytest.mark.converter
37
+ @pytest.mark.elf
38
+ @pytest.mark.parametrize("file", examples_fw)
39
+ def test_example_scripts_fw(example_path: Path, file: str) -> None:
40
+ subprocess.check_call(f"python {example_path / file}", shell=True)
tests/test_writer.py CHANGED
@@ -140,7 +140,7 @@ def test_writer_align(h5_path: Path) -> None:
140
140
  data_nd = np.zeros((int(length),))
141
141
  sfw.append_iv_data_raw(time_nd, data_nd, data_nd)
142
142
  with Reader(h5_path) as sfr:
143
- assert sfr.ds_time.size < length
143
+ assert sfr.ds_voltage.size < length
144
144
 
145
145
 
146
146
  def test_writer_not_align(h5_path: Path) -> None:
@@ -151,7 +151,7 @@ def test_writer_not_align(h5_path: Path) -> None:
151
151
  data_nd = np.zeros((int(length),))
152
152
  sfw.append_iv_data_raw(time_nd, data_nd, data_nd)
153
153
  with Reader(h5_path) as sfr:
154
- assert sfr.ds_time.size == length
154
+ assert sfr.ds_voltage.size == length
155
155
 
156
156
 
157
157
  def test_writer_setter(h5_path: Path) -> None:
tests/vsource/conftest.py CHANGED
@@ -9,9 +9,7 @@ from shepherd_data import mppt
9
9
 
10
10
  @pytest.fixture
11
11
  def file_ivonne() -> Path:
12
- path = (
13
- Path(__file__).resolve().parent.parent.parent.parent / "shepherd_data/examples"
14
- )
12
+ path = Path(__file__).resolve().parent.parent.parent.parent / "shepherd_data/examples"
15
13
  os.chdir(path)
16
14
  return path / "./jogging_10m.iv"
17
15
 
@@ -146,9 +146,7 @@ def test_vsource_vsrc_sim_curve(src_name: str, file_ivcurve: Path) -> None:
146
146
  for _t, _v, _i in file.read_buffers():
147
147
  length = max(_v.size, _i.size)
148
148
  for _n in range(length):
149
- src.iterate_sampling(
150
- V_inp_uV=_v[_n] * 10**6, I_inp_nA=_i[_n] * 10**9
151
- )
149
+ src.iterate_sampling(V_inp_uV=_v[_n] * 10**6, I_inp_nA=_i[_n] * 10**9)
152
150
 
153
151
 
154
152
  @pytest.mark.parametrize("src_name", src_list)
@@ -160,6 +158,4 @@ def test_vsource_vsrc_sim_sample(src_name: str, file_ivsample: Path) -> None:
160
158
  for _t, _v, _i in file.read_buffers():
161
159
  length = max(_v.size, _i.size)
162
160
  for _n in range(length):
163
- src.iterate_sampling(
164
- V_inp_uV=_v[_n] * 10**6, I_inp_nA=_i[_n] * 10**9
165
- )
161
+ src.iterate_sampling(V_inp_uV=_v[_n] * 10**6, I_inp_nA=_i[_n] * 10**9)
@@ -39,9 +39,7 @@ def test_vsource_hrv_fail_ivcurve(hrv_name: str) -> None:
39
39
  # the first algos are not usable for ivcurve
40
40
  with pytest.raises(ValueError):
41
41
  hrv_config = VirtualHarvesterConfig(name=hrv_name)
42
- _ = HarvesterPRUConfig.from_vhrv(
43
- hrv_config, for_emu=True, dtype_in=EnergyDType.ivcurve
44
- )
42
+ _ = HarvesterPRUConfig.from_vhrv(hrv_config, for_emu=True, dtype_in=EnergyDType.ivcurve)
45
43
 
46
44
 
47
45
  @pytest.mark.parametrize("hrv_name", hrv_list[3:])
@@ -58,9 +56,7 @@ def test_vsource_hrv_sim(hrv_name: str, file_ivcurve: Path) -> None:
58
56
  for _t, _v, _i in file.read_buffers():
59
57
  length = max(_v.size, _i.size)
60
58
  for _n in range(length):
61
- hrv.ivcurve_sample(
62
- _voltage_uV=_v[_n] * 10**6, _current_nA=_i[_n] * 10**9
63
- )
59
+ hrv.ivcurve_sample(_voltage_uV=_v[_n] * 10**6, _current_nA=_i[_n] * 10**9)
64
60
 
65
61
 
66
62
  @pytest.mark.parametrize("hrv_name", hrv_list[3:])
@@ -68,9 +64,7 @@ def test_vsource_hrv_fail_isc_voc(hrv_name: str) -> None:
68
64
  # not implemented ATM
69
65
  with pytest.raises(ValueError):
70
66
  hrv_config = VirtualHarvesterConfig(name=hrv_name)
71
- _ = HarvesterPRUConfig.from_vhrv(
72
- hrv_config, for_emu=True, dtype_in=EnergyDType.isc_voc
73
- )
67
+ _ = HarvesterPRUConfig.from_vhrv(hrv_config, for_emu=True, dtype_in=EnergyDType.isc_voc)
74
68
 
75
69
 
76
70
  def test_vsource_hrv_fail_unknown_type() -> None: