Coverage for jumpstarter_driver_flashers/test_bundle.py: 100%

28 statements  

« prev     ^ index     » next       coverage.py v7.9.1, created at 2025-06-30 18:45 +0200

1from pathlib import Path 

2 

3import pytest 

4 

5from . import bundle 

6 

7 

8def test_bundle_read(): 

9 # get current package directory 

10 manifest_file = Path(__file__).parent / "../oci_bundles/ti_j784s4xevm/manifest.yaml" 

11 flasher_bundle = bundle.FlasherBundleManifestV1Alpha1.from_file(manifest_file) 

12 assert flasher_bundle.apiVersion == "jumpstarter.dev/v1alpha1" 

13 assert flasher_bundle.kind == "FlashBundleManifest" 

14 assert flasher_bundle.spec.targets == { 

15 "usd": "/sys/class/block#4fb0000", 

16 "emmc": "/sys/class/block#4f80000", 

17 } 

18 

19 

20def test_bundle_get_boot_cmd_default(): 

21 """Test getting default boot command from test bundle""" 

22 manifest_file = Path(__file__).parent / "../oci_bundles/test/manifest.yaml" 

23 flasher_bundle = bundle.FlasherBundleManifestV1Alpha1.from_file(manifest_file) 

24 

25 # Test default boot command (no variant specified) 

26 bootcmd = flasher_bundle.get_boot_cmd() 

27 assert bootcmd == "booti 0x82000000 - 0x84000000" 

28 

29 

30def test_bundle_get_boot_cmd_with_variant(): 

31 """Test getting boot command with specific DTB variant""" 

32 manifest_file = Path(__file__).parent / "../oci_bundles/test/manifest.yaml" 

33 flasher_bundle = bundle.FlasherBundleManifestV1Alpha1.from_file(manifest_file) 

34 

35 # Test variant with custom boot command 

36 bootcmd = flasher_bundle.get_boot_cmd("othercmd") 

37 assert bootcmd == "bootm" 

38 

39 # Test variant without custom boot command (should use default) 

40 bootcmd = flasher_bundle.get_boot_cmd("alternate") 

41 assert bootcmd == "booti 0x82000000 - 0x84000000" 

42 

43 # Test default variant explicitly 

44 bootcmd = flasher_bundle.get_boot_cmd("test-dtb") 

45 assert bootcmd == "booti 0x82000000 - 0x84000000" 

46 

47 

48def test_bundle_get_boot_cmd_invalid_variant(): 

49 """Test that get_boot_cmd raises ValueError for invalid variant""" 

50 manifest_file = Path(__file__).parent / "../oci_bundles/test/manifest.yaml" 

51 flasher_bundle = bundle.FlasherBundleManifestV1Alpha1.from_file(manifest_file) 

52 

53 with pytest.raises(ValueError, match="DTB variant noexists not found in the manifest"): 

54 flasher_bundle.get_boot_cmd("noexists")