forked from microsoft/vscode-python-debugger
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_update_ext_version.py
More file actions
104 lines (92 loc) · 3.13 KB
/
test_update_ext_version.py
File metadata and controls
104 lines (92 loc) · 3.13 KB
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
93
94
95
96
97
98
99
100
101
102
103
104
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
import json
import freezegun
import pytest
import update_ext_version
TEST_DATETIME = "2022-03-14 01:23:45"
# The build ID is calculated via:
# "1" + datetime.datetime.strptime(TEST_DATETIME,"%Y-%m-%d %H:%M:%S").strftime('%j%H%M')
EXPECTED_BUILD_ID = "10730123"
def create_package_json(directory, version):
"""Create `package.json` in `directory` with a specified version of `version`."""
package_json = directory / "package.json"
package_json.write_text(json.dumps({"version": version}), encoding="utf-8")
return package_json
def run_test(tmp_path, version, args, expected):
package_json = create_package_json(tmp_path, version)
update_ext_version.main(package_json, args)
package = json.loads(package_json.read_text(encoding="utf-8"))
assert expected == update_ext_version.parse_version(package["version"])
@pytest.mark.parametrize(
"version, args",
[
("1.0.0-rc", []),
("1.1.0-rc", ["--release"]),
("1.0.0-rc", ["--release", "--build-id", "-1"]),
("1.0.0-rc", ["--release", "--for-publishing", "--build-id", "-1"]),
("1.0.0-rc", ["--release", "--for-publishing", "--build-id", "999999999999"]),
("1.1.0-rc", ["--build-id", "-1"]),
("1.1.0-rc", ["--for-publishing", "--build-id", "-1"]),
("1.1.0-rc", ["--for-publishing", "--build-id", "999999999999"]),
],
)
def test_invalid_args(tmp_path, version, args):
with pytest.raises(ValueError):
run_test(tmp_path, version, args, None)
@pytest.mark.parametrize(
"version, args, expected",
[
("1.1.0-rc", ["--build-id", "12345"], ("1", "1", "12345", "rc")),
("1.0.0-rc", ["--release", "--build-id", "12345"], ("1", "0", "12345", "")),
(
"1.1.0-rc",
["--for-publishing", "--build-id", "12345"],
("1", "1", "12345", ""),
),
(
"1.0.0-rc",
["--release", "--for-publishing", "--build-id", "12345"],
("1", "0", "12345", ""),
),
(
"1.0.0-rc",
["--release", "--build-id", "999999999999"],
("1", "0", "999999999999", ""),
),
(
"1.1.0-rc",
["--build-id", "999999999999"],
("1", "1", "999999999999", "rc"),
),
("1.1.0-rc", [], ("1", "1", EXPECTED_BUILD_ID, "rc")),
(
"1.0.0-rc",
["--release"],
("1", "0", "0", ""),
),
(
"1.1.0-rc",
["--for-publishing"],
("1", "1", EXPECTED_BUILD_ID, ""),
),
(
"1.0.0-rc",
["--release", "--for-publishing"],
("1", "0", "0", ""),
),
(
"1.0.0-rc",
["--release"],
("1", "0", "0", ""),
),
(
"1.1.0-rc",
[],
("1", "1", EXPECTED_BUILD_ID, "rc"),
),
],
)
@freezegun.freeze_time("2022-03-14 01:23:45")
def test_update_ext_version(tmp_path, version, args, expected):
run_test(tmp_path, version, args, expected)