Line 0
Link Here
|
0 |
- |
1 |
# Copyright 2019 Gentoo Authors |
|
|
2 |
|
3 |
import os |
4 |
import shutil |
5 |
import tempfile |
6 |
import unittest |
7 |
|
8 |
from mirrorselect.configs import write_make_conf |
9 |
from mirrorselect.output import Output |
10 |
|
11 |
|
12 |
class WriteMakeConfTestCase(unittest.TestCase): |
13 |
def test_write_make_conf(self): |
14 |
|
15 |
var = 'GENTOO_MIRRORS' |
16 |
mirror_string = '{}="a b"'.format(var) |
17 |
|
18 |
cases = ( |
19 |
('{}="foo\nbar"\n'.format(var), '{}\n'.format(mirror_string)), |
20 |
('\n{}="foo\nbar"\n'.format(var), '\n{}\n'.format(mirror_string)), |
21 |
('\n{}="foo bar"\n'.format(var), '\n{}\n'.format(mirror_string)), |
22 |
('\n{}="foo bar"\n\n'.format(var), '\n\n{}\n'.format(mirror_string)), |
23 |
('\n{}="foo \\\nbar"\n'.format(var), '\n{}\n'.format(mirror_string)), |
24 |
('\n\n{}="foo \\\nbar"\n'.format(var), '\n\n{}\n'.format(mirror_string)), |
25 |
('\n\n{}="foo \\\nbar"\na="b"\n'.format(var), '\n\na="b"\n{}\n'.format(mirror_string)), |
26 |
) |
27 |
|
28 |
for make_conf, expected_result in cases: |
29 |
tempdir = tempfile.mkdtemp() |
30 |
status_output = open(os.devnull, 'w') |
31 |
try: |
32 |
config_path = os.path.join(tempdir, 'make.conf') |
33 |
with open(config_path, 'wt') as f: |
34 |
f.write(make_conf) |
35 |
write_make_conf(Output(out=status_output), config_path, var, mirror_string) |
36 |
with open(config_path, 'rt') as f: |
37 |
result = f.read() |
38 |
self.assertEqual(result, expected_result) |
39 |
finally: |
40 |
shutil.rmtree(tempdir) |
41 |
status_output.close() |