Coverage for tests/test_extension.py: 100.00%

19 statements  

« prev     ^ index     » next       coverage.py v7.10.6, created at 2025-09-05 17:33 +0200

1"""Test the extension.""" 

2 

3import griffe 

4 

5 

6def test_objects_imported_within_same_package() -> None: 

7 """Objects imported with redundant aliases as marked as public.""" 

8 with griffe.temporary_visited_package( 

9 "package", 

10 { 

11 "__init__.py": "from package.module import Thing as Thing, Stuff", 

12 "module.py": "class Thing: ...\nclass Stuff: ...", 

13 }, 

14 extensions=griffe.load_extensions("griffe_public_redundant_aliases"), 

15 ) as package: 

16 assert package["Thing"].public 

17 assert package["Thing"].is_public 

18 assert package["Stuff"].public is None 

19 assert not package["Stuff"].is_public 

20 

21 

22def test_objects_imported_from_external_package() -> None: 

23 """Objects imported with redundant aliases as marked as public.""" 

24 with griffe.temporary_visited_module( 

25 "from external import Thing as Thing, Stuff", 

26 extensions=griffe.load_extensions("griffe_public_redundant_aliases"), 

27 ) as package: 

28 assert package["Thing"].public 

29 assert package["Thing"].is_public 

30 assert package["Stuff"].public is None 

31 assert not package["Stuff"].is_public 

32 

33 

34def test_not_stoping_too_early() -> None: 

35 """Don't stop too early on several aliases of the same object.""" 

36 with griffe.temporary_visited_module( 

37 "from external import Thing as Stuff, Thing as Thing", 

38 extensions=griffe.load_extensions("griffe_public_redundant_aliases"), 

39 ) as package: 

40 assert package["Thing"].public 

41 assert package["Thing"].is_public 

42 assert package["Stuff"].public is None 

43 assert not package["Stuff"].is_public