Coverage for bioimageio/core/utils/_compare.py: 89%

9 statements  

« prev     ^ index     » next       coverage.py v7.8.0, created at 2025-04-01 09:51 +0000

1from difflib import HtmlDiff, unified_diff 

2from typing import Sequence 

3 

4from typing_extensions import Literal, assert_never 

5 

6 

7def compare( 

8 a: Sequence[str], 

9 b: Sequence[str], 

10 name_a: str = "source", 

11 name_b: str = "updated", 

12 *, 

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

14): 

15 if diff_format == "html": 

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

17 elif diff_format == "unified": 

18 diff = "\n".join( 

19 unified_diff( 

20 a, 

21 b, 

22 name_a, 

23 name_b, 

24 lineterm="", 

25 ) 

26 ) 

27 else: 

28 assert_never(diff_format) 

29 

30 return diff