1 |
commit: a09b4d302e4cee79254d3ff4a5ac9f080b958acf |
2 |
Author: Brian Dolbec <dolsen <AT> gentoo <DOT> org> |
3 |
AuthorDate: Tue May 31 17:58:14 2022 +0000 |
4 |
Commit: Brian Dolbec <dolsen <AT> gentoo <DOT> org> |
5 |
CommitDate: Tue May 31 17:58:14 2022 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/mirrorselect.git/commit/?id=a09b4d30 |
7 |
|
8 |
main.py: Add indented backslash capability to multilne GENTOO_MIRRORS |
9 |
|
10 |
For multiple mirrors, use backslashes list additional mirrors with |
11 |
indents for clarity. |
12 |
|
13 |
Gentoo-bug-url: https://bugs.gentoo.org/543814 |
14 |
|
15 |
Signed-off-by: Brian Dolbec <dolsen <AT> gentoo.org> |
16 |
|
17 |
mirrorselect/main.py | 2 +- |
18 |
tests/test_write_make_conf.py | 59 ++++++++++++++++++++++++++----------------- |
19 |
2 files changed, 37 insertions(+), 24 deletions(-) |
20 |
|
21 |
diff --git a/mirrorselect/main.py b/mirrorselect/main.py |
22 |
old mode 100644 |
23 |
new mode 100755 |
24 |
index 8a3094e..31f8e7b |
25 |
--- a/mirrorselect/main.py |
26 |
+++ b/mirrorselect/main.py |
27 |
@@ -109,7 +109,7 @@ class MirrorSelect(object): |
28 |
if var == "sync-uri" and out: |
29 |
mirror_string = '%s = %s' % (var, ' '.join(hosts)) |
30 |
else: |
31 |
- mirror_string = '%s="%s"' % (var, ' '.join(hosts)) |
32 |
+ mirror_string = '%s="%s"' % (var, ' \\\n '.join(hosts)) |
33 |
|
34 |
if out: |
35 |
self.write_to_output(mirror_string) |
36 |
|
37 |
diff --git a/tests/test_write_make_conf.py b/tests/test_write_make_conf.py |
38 |
index fb84978..5d13bf5 100644 |
39 |
--- a/tests/test_write_make_conf.py |
40 |
+++ b/tests/test_write_make_conf.py |
41 |
@@ -12,31 +12,44 @@ from mirrorselect.output import Output |
42 |
class WriteMakeConfTestCase(unittest.TestCase): |
43 |
def test_write_make_conf(self): |
44 |
|
45 |
+ def __do_it(var, mirror_string, make_conf, expected_result): |
46 |
+ tempdir = tempfile.mkdtemp() |
47 |
+ status_output = open(os.devnull, 'w') |
48 |
+ #print("------make_conf--------", make_conf, "----------------------") |
49 |
+ #print("*****expect*****\n", expected_result, "***********") |
50 |
+ try: |
51 |
+ config_path = os.path.join(tempdir, 'make.conf') |
52 |
+ with open(config_path, 'wt') as f: |
53 |
+ f.write(make_conf) |
54 |
+ write_make_conf(Output(out=status_output), config_path, var, mirror_string) |
55 |
+ with open(config_path, 'rt') as f: |
56 |
+ result = f.read() |
57 |
+ #print("!!!result!!!\n", result, "!!!!!!!!!!\n") |
58 |
+ self.assertEqual(result, "{}".format(expected_result).format(mirror_string)) |
59 |
+ finally: |
60 |
+ shutil.rmtree(tempdir) |
61 |
+ status_output.close() |
62 |
+ |
63 |
var = 'GENTOO_MIRRORS' |
64 |
- mirror_string = '{}="a b"'.format(var) |
65 |
+ mirrors = ( |
66 |
+ ('{}="a"'.format(var)), |
67 |
+ ('{}="a b"'.format(var)), |
68 |
+ ('{}="a b c"'.format(var)), |
69 |
+ ) |
70 |
|
71 |
cases = ( |
72 |
- ('{}="foo\nbar"\n'.format(var), '{}\n'.format(mirror_string)), |
73 |
- ('\n{}="foo\nbar"\n'.format(var), '\n{}\n'.format(mirror_string)), |
74 |
- ('\n{}="foo bar"\n'.format(var), '\n{}\n'.format(mirror_string)), |
75 |
- ('\n{}="foo bar"\n\n'.format(var), '\n\n{}\n'.format(mirror_string)), |
76 |
- ('\n{}="foo \\\nbar"\n'.format(var), '\n{}\n'.format(mirror_string)), |
77 |
- ('\n\n{}="foo \\\nbar"\n'.format(var), '\n\n{}\n'.format(mirror_string)), |
78 |
- ('\n\n{}="foo \\\nbar"\na="b"\n'.format(var), '\n\na="b"\n{}\n'.format(mirror_string)), |
79 |
- ('', '{}\n'.format(mirror_string)), |
80 |
+ ('{}="foo\nbar"\n'.format(var), '{}\n'), |
81 |
+ ('\n{}="foo\nbar"\n'.format(var), '\n{}\n'), |
82 |
+ ('\n{}="foo bar"\n'.format(var), '\n{}\n'), |
83 |
+ ('\n{}="foo bar"\n\n'.format(var), '\n\n{}\n'), |
84 |
+ ('\n{}="foo \\\nbar"\n'.format(var), '\n{}\n'), |
85 |
+ ('\n\n{}="foo \\\nbar"\n'.format(var), '\n\n{}\n'), |
86 |
+ ('\n\n{}="foo \\\nbar"\na="b"\n'.format(var), '\n\na="b"\n{}\n'), |
87 |
+ ('\n\n{}="foo \\\n bar"\na="b"\n'.format(var), '\n\na="b"\n{}\n'), |
88 |
+ ('\n\n{}="foo \\\n bar\\\n baz"\na="b"\n'.format(var), '\n\na="b"\n{}\n'), |
89 |
+ ('', '{}\n'), |
90 |
) |
91 |
|
92 |
- for make_conf, expected_result in cases: |
93 |
- tempdir = tempfile.mkdtemp() |
94 |
- status_output = open(os.devnull, 'w') |
95 |
- try: |
96 |
- config_path = os.path.join(tempdir, 'make.conf') |
97 |
- with open(config_path, 'wt') as f: |
98 |
- f.write(make_conf) |
99 |
- write_make_conf(Output(out=status_output), config_path, var, mirror_string) |
100 |
- with open(config_path, 'rt') as f: |
101 |
- result = f.read() |
102 |
- self.assertEqual(result, expected_result) |
103 |
- finally: |
104 |
- shutil.rmtree(tempdir) |
105 |
- status_output.close() |
106 |
+ for mirror in mirrors: |
107 |
+ for make_conf, expected_result in cases: |
108 |
+ __do_it(var, mirror, make_conf, expected_result) |