-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathconfig_test.py
86 lines (78 loc) · 2.62 KB
/
config_test.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
# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from nanoemoji import config
from pathlib import Path
import pytest
from test_helper import test_data_dir, locate_test_file
import shutil
import tempfile
from typing import Iterable
@pytest.mark.parametrize(
"config_file",
[
None, # the default config file
"minimal_vf/config.toml",
"minimal_static/config.toml",
],
)
def test_read_write_config(config_file):
tmp_dir = Path(tempfile.mkdtemp())
if config_file:
config_file = locate_test_file(config_file)
tmp_config = tmp_dir / config_file.name
else:
tmp_config = tmp_dir / "the_default.toml"
original = config.load(config_file)
config.write(tmp_config, original)
reloaded = config.load(tmp_config)
assert original == reloaded
shutil.rmtree(tmp_dir, ignore_errors=True)
@pytest.mark.parametrize(
"relative_base, src, expected_files",
[
# relative single file
(
test_data_dir(),
"minimal_static/svg/61.svg",
{locate_test_file("minimal_static/svg/61.svg")},
),
# relative pattern
(
test_data_dir(),
"linear_gradient_transform*.svg",
{
locate_test_file("linear_gradient_transform.svg"),
locate_test_file("linear_gradient_transform_2.svg"),
locate_test_file("linear_gradient_transform_3.svg"),
},
),
# absolute single file
(
test_data_dir(),
locate_test_file("minimal_static/svg/61.svg").resolve(),
{locate_test_file("minimal_static/svg/61.svg")},
),
# absolute pattern
(
None,
test_data_dir().resolve() / "**" / "linear_gradient_transform_*.svg",
{
locate_test_file("linear_gradient_transform_2.svg"),
locate_test_file("linear_gradient_transform_3.svg"),
},
),
],
)
def test_resolve_src(relative_base, src, expected_files):
assert set(config._resolve_src(relative_base, str(src))) == expected_files