Coverage for tests/integration_tests/test_packages_checker.py: 100%

21 statements  

« prev     ^ index     » next       coverage.py v7.16.1, created at 2026-09-23 03:53 +0000

1""" 

2Test the package checking functionality. This is a sanity checker that is 

3implemented by packages.check_packages() and invoked from a few places. 

4""" 

5 

6import os 

7import json 

8import shutil 

9from tests.conftest import ApioRunner 

10from apio.commands.apio import apio_top_cli as apio 

11 

12 

13def test_yosys_release_tag_mismatch(apio_runner: ApioRunner): 

14 """Test the verification that the apio 'oss-cad-suite' and 'openxc7' 

15 use the same Yosys release.""" 

16 

17 with apio_runner.in_sandbox() as sb: 

18 

19 # -- Fetch an example, this also verifies that the apio packages are 

20 # -- installed. 

21 result = sb.invoke_apio_cmd( 

22 apio, ["examples", "fetch", "basys3/blinky"] 

23 ) 

24 sb.assert_result_ok(result) 

25 

26 # -- Make a copy of the packages dir so we don't disturb the original. 

27 # -- This is because the packages are cached and shared between tests. 

28 # -- We create the fake package dir under the private sandbox of this 

29 # -- test instance which is deleted at the end of the test. 

30 fake_packages_dir = sb.sandbox_dir / "fake_packages_dir" 

31 shutil.copytree( 

32 sb.packages_dir, fake_packages_dir, dirs_exist_ok=False 

33 ) 

34 

35 # -- Set the fake packages dir as the default packages dir for apio. 

36 # -- This env is also cleared automatically by conftest.py at the end 

37 # -- of this test. 

38 os.environ["APIO_PACKAGES"] = str(fake_packages_dir) 

39 

40 # -- Modify of the 'yosys-release-tag' of the 'oss-cad-suite' to 

41 # -- create a fake mismatch. 

42 build_info_path = ( 

43 fake_packages_dir / "oss-cad-suite" / "BUILD-INFO.json" 

44 ) 

45 

46 with open(build_info_path, encoding="utf-8") as f: 

47 build_info_data = json.load(f) 

48 

49 build_info_data["yosys-release-tag"] = "2026-01-01" 

50 

51 with open(build_info_path, "w", encoding="utf-8") as f: 

52 json.dump(build_info_data, f, indent=2) 

53 

54 # -- Now run the apio build and it should check and fail on 

55 # -- yosys-release-tag mismatch, even if the build is already up to 

56 # -- date. 

57 result = sb.invoke_apio_cmd(apio, ["build"]) 

58 assert result.exit_code == 1 

59 assert 'were built with different "yosys-release-tag"' in result.output