Coverage for src/bioimageio/core/_utils/compare.py: 75%

20 statements  

« prev     ^ index     » next       coverage.py v7.17.3, created at 2026-11-20 09:46 +0000

1from collections.abc import Sequence 

2from difflib import HtmlDiff, unified_diff 

3from typing import Literal 

4 

5from loguru import logger 

6from ruyaml import Optional 

7from typing_extensions import assert_never 

8 

9from bioimageio.spec._internal.version_type import Version 

10 

11 

12def compare( 

13 a: Sequence[str], 

14 b: Sequence[str], 

15 name_a: str = "source", 

16 name_b: str = "updated", 

17 *, 

18 diff_format: Literal["unified", "html"], 

19): 

20 if diff_format == "html": 20 ↛ 21line 20 didn't jump to line 21 because the condition on line 20 was never true

21 diff = HtmlDiff().make_file(a, b, name_a, name_b, charset="utf-8") 

22 elif diff_format == "unified": 

23 diff = "\n".join( 

24 unified_diff( 

25 a, 

26 b, 

27 name_a, 

28 name_b, 

29 lineterm="", 

30 ) 

31 ) 

32 else: 

33 assert_never(diff_format) 

34 

35 return diff 

36 

37 

38def warn_about_version( 

39 name: str, specified_version: Optional[Version], actual_version: Optional[Version] 

40) -> None: 

41 if actual_version is None or specified_version is None: 41 ↛ 42line 41 didn't jump to line 42 because the condition on line 41 was never true

42 logger.warning("Could not compare actual and installed {} versions.", name) 

43 elif actual_version < specified_version: 43 ↛ 44line 43 didn't jump to line 44 because the condition on line 43 was never true

44 logger.warning( 

45 "Installed {} version {} is lower than specified version {}.", 

46 name, 

47 actual_version, 

48 specified_version, 

49 ) 

50 elif (specified_version.major, specified_version.minor) != ( 50 ↛ exitline 50 didn't return from function 'warn_about_version' because the condition on line 50 was always true

51 actual_version.major, 

52 actual_version.minor, 

53 ): 

54 logger.warning( 

55 "Installed {} version {} does not match specified {}.", 

56 name, 

57 actual_version, 

58 specified_version, 

59 )