Coverage for Users/vladimirpavlov/PycharmProjects/parameterizable/tests/test_version.py: 94%

1 import re

2

3 import pytest

4

5 import mixinforge

6

7

8 def test_version_exists():

9 """

10 Test that __version__ attribute exists and is accessible.

11 """

12 assert hasattr(mixinforge, '__version__')

13 assert mixinforge.__version__ is not None

14

15

16 def test_version_is_string():

17 """

18 Test that __version__ is a string.

19 """

20 assert isinstance(mixinforge.__version__, str)

21 assert len(mixinforge.__version__) > 0

22

23

24 def test_version_follows_semantic_versioning():

25 """

26 Test that __version__ follows semantic versioning format (X.Y.Z).

27 """

28 # Basic semantic versioning pattern: major.minor.patch

29 # May also include pre-release identifiers (alpha, beta, rc)

30 semver_pattern = r'^\d+\.\d+\.\d+(?:[-.]?(?:a|alpha|b|beta|rc|dev)\d*)?$'

31 assert re.match(semver_pattern, mixinforge.__version__)

32

33

34 def test_version_accessible_from_metadata():

35 """

36 Test that __version__ can be accessed and is consistent with importlib.metadata.

37 """

38 from importlib import metadata

39

40 # Test that we can get version from metadata (this is how it's implemented)

41 try:

42 metadata_version = metadata.version("mixinforge")

43 # The __version__ should match what metadata reports

44 assert mixinforge.__version__ == metadata_version

45 except Exception as e:

46 # If metadata lookup fails, at least ensure __version__ exists and is valid

47 pytest.fail(f"Could not retrieve version from metadata: {e}")

48

49

50 def test_version_format_compatibility():

51 """

52 Test that __version__ can be compared and parsed as a version string.

53 """

54 # Split version into components

55 parts = mixinforge.__version__.split('.')

56

57 # Verify we can parse major, minor, patch version numbers

58 assert len(parts) >= 3

59 assert all(p.isdigit() for p in parts[:3])

60

61 major = int(parts[0])

62 minor = int(parts[1])

63 patch = int(parts[2])

64

65 # Test that version components are integers >= 0

66 assert major >= 0

67 assert minor >= 0

68 assert patch >= 0

69

70

71 def test_version_in_all():

72 """

73 Test that __version__ is included in the __all__ list.

74 """

75 assert '__version__' in mixinforge.__all__