forked from OSGeo/grass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_generate_last_commit_file.py
92 lines (71 loc) · 2.17 KB
/
test_generate_last_commit_file.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/env python3
"""
Script for testing an core_modules_with_last_commit.json file contains
all core modules with their last commit. Used by GitHub "Additional Checks"
action workflow.
Python lib dependencies:
pytest
pytest-depends
Usage:
pytest utils/test_generate_last_commit_file.py
@author Tomas Zigo <tomas.zigo slovanet.sk>
"""
import os
import json
import subprocess
import pytest
from .generate_last_commit_file import COMMIT_DATE_FORMAT
@pytest.fixture
def json_file():
return "core_modules_with_last_commit.json"
@pytest.fixture
def read_json_file(json_file):
with open(json_file) as f:
return json.load(f)
def test_json_file_exists(json_file):
assert os.path.exists(json_file) is True
@pytest.mark.depends(on=["test_json_file_exists"])
def test_json_file_is_not_empty(read_json_file):
assert len(read_json_file) > 0
@pytest.mark.depends(on=["test_json_file_is_not_empty"])
@pytest.mark.parametrize(
"core_module_path",
[
os.path.join("vector", "v.surf.rst"),
os.path.join("raster", "r.info"),
],
)
def test_core_modules_in_json_file(read_json_file, core_module_path):
core_module = os.path.basename(core_module_path)
assert core_module in read_json_file
@pytest.mark.depends(
on=[
"test_json_file_is_not_empty",
"test_core_modules_in_json_file",
]
)
@pytest.mark.parametrize(
"core_module_path",
[
os.path.join("vector", "v.surf.rst"),
os.path.join("raster", "r.info"),
],
)
def test_compare_json_file_data(read_json_file, core_module_path):
# Get Git commit and commit date from local Git
process_result = subprocess.run(
[
"git",
"log",
"-1",
f"--format=%H,{COMMIT_DATE_FORMAT}",
core_module_path,
],
capture_output=True,
check=True,
) # --format=%H,COMMIT_DATE_FORMAT commit hash,author date
commit, date = process_result.stdout.decode().strip().split(",")
core_module = os.path.basename(core_module_path)
# Compare commit and commit date
assert read_json_file[core_module]["commit"] == commit
assert read_json_file[core_module]["date"] == date