1
1
import dataclasses
2
2
import json
3
+ from pathlib import Path
4
+ from unittest import mock
3
5
4
- from build_versions .dockerfiles import render_dockerfile_with_context
5
- from build_versions .settings import DOCKERFILES_PATH
6
- from build_versions .versions import BuildVersion , scrape_supported_python_versions
7
-
6
+ import pytest
8
7
9
- def test_scrape_supported_python_versions () -> None :
10
- versions = scrape_supported_python_versions ()
11
- assert len (versions ) > 0
12
- first_version = versions [0 ]
13
- assert first_version .version
14
- assert first_version .start
15
- assert first_version .end
8
+ from build_versions .dockerfiles import render_dockerfile_with_context
9
+ from build_versions .readme import update_dynamic_readme
10
+ from build_versions .settings import BASE_PATH , DOCKERFILES_PATH
11
+ from build_versions .versions import (
12
+ BuildVersion ,
13
+ SupportedVersion ,
14
+ scrape_supported_python_versions ,
15
+ )
16
16
17
17
18
- def test_render_dockerfile_with_context () -> None :
19
- build_config = BuildVersion (
18
+ @pytest .fixture (name = "build_version" )
19
+ def build_version_fixture () -> BuildVersion :
20
+ return BuildVersion (
20
21
key = "python3.11-nodejs20" ,
21
22
python = "3.11" ,
22
23
python_canonical = "3.11.3" ,
@@ -29,11 +30,73 @@ def test_render_dockerfile_with_context() -> None:
29
30
"linux/arm64" ,
30
31
],
31
32
)
32
- file_path = DOCKERFILES_PATH / f"{ build_config .key } .Dockerfile"
33
- render_dockerfile_with_context (json .dumps (dataclasses .asdict (build_config )))
33
+
34
+
35
+ def test_scrape_supported_python_versions () -> None :
36
+ versions = scrape_supported_python_versions ()
37
+ assert len (versions ) > 0
38
+ first_version = versions [0 ]
39
+ assert first_version .version
40
+ assert first_version .start
41
+ assert first_version .end
42
+
43
+
44
+ def test_render_dockerfile_with_context (build_version : BuildVersion ) -> None :
45
+ file_path = DOCKERFILES_PATH / f"{ build_version .key } .Dockerfile"
46
+ render_dockerfile_with_context (json .dumps (dataclasses .asdict (build_version )))
34
47
assert file_path .exists ()
35
48
with file_path .open () as fp :
36
49
dockerfile = fp .read ()
37
50
38
- assert f"# python: { build_config .python_canonical } " in dockerfile
39
- assert f"# nodejs: { build_config .nodejs_canonical } " in dockerfile
51
+ assert f"# python: { build_version .python_canonical } " in dockerfile
52
+ assert f"# nodejs: { build_version .nodejs_canonical } " in dockerfile
53
+
54
+
55
+ class MockPath :
56
+ content : str = ""
57
+
58
+ def __init__ (self : "MockPath" , content : str ) -> None :
59
+ self .content = content
60
+
61
+ def write_text (self : "MockPath" , text : str ) -> None :
62
+ self .content = text
63
+
64
+ def read_text (self : "MockPath" ) -> str :
65
+ return self .content
66
+
67
+
68
+ def test_update_dynamic_readme (build_version : BuildVersion ) -> None :
69
+ ver = build_version
70
+ python_version = SupportedVersion (start = "2022-10-24" , end = "2027-10" , version = "3.11" )
71
+ node_version = SupportedVersion (start = "2023-04-18" , end = "2026-04-30" , version = "v20" )
72
+ initial_content = """
73
+ ## Tags
74
+
75
+ <!-- TAGS_START -->
76
+
77
+ <!-- TAGS_END -->
78
+
79
+ ## Supported Versions
80
+
81
+ <!-- SUPPORTED_VERSIONS_START -->
82
+
83
+ <!-- SUPPORTED_VERSIONS_END -->
84
+ """
85
+ mock_path = MockPath (initial_content )
86
+
87
+ with mock .patch .multiple (
88
+ Path ,
89
+ read_text = mock_path .read_text ,
90
+ write_text = mock_path .write_text ,
91
+ ):
92
+ update_dynamic_readme ([ver ], [python_version ], [node_version ])
93
+
94
+ file_path = BASE_PATH / "README.md"
95
+ assert file_path .exists ()
96
+ readme = file_path .read_text ()
97
+ assert (
98
+ f"`{ ver .key } ` | { ver .python_canonical } | { ver .nodejs_canonical } | { ver .distro } | { ', ' .join (ver .platforms )} "
99
+ in readme
100
+ )
101
+ assert f"{ python_version .version } | { python_version .start } | { python_version .end } " in readme
102
+ assert f"{ node_version .version } | { node_version .start } | { node_version .end } " in readme
0 commit comments