From a09b4d302e4cee79254d3ff4a5ac9f080b958acf Mon Sep 17 00:00:00 2001 From: Brian Dolbec Date: Tue, 31 May 2022 10:58:14 -0700 Subject: main.py: Add indented backslash capability to multilne GENTOO_MIRRORS For multiple mirrors, use backslashes list additional mirrors with indents for clarity. Gentoo-bug-url: https://bugs.gentoo.org/543814 Signed-off-by: Brian Dolbec --- mirrorselect/main.py | 2 +- tests/test_write_make_conf.py | 59 ++++++++++++++++++++++++++----------------- 2 files changed, 37 insertions(+), 24 deletions(-) mode change 100644 => 100755 mirrorselect/main.py diff --git a/mirrorselect/main.py b/mirrorselect/main.py old mode 100644 new mode 100755 index 8a3094e..31f8e7b --- a/mirrorselect/main.py +++ b/mirrorselect/main.py @@ -109,7 +109,7 @@ class MirrorSelect(object): if var == "sync-uri" and out: mirror_string = '%s = %s' % (var, ' '.join(hosts)) else: - mirror_string = '%s="%s"' % (var, ' '.join(hosts)) + mirror_string = '%s="%s"' % (var, ' \\\n '.join(hosts)) if out: self.write_to_output(mirror_string) diff --git a/tests/test_write_make_conf.py b/tests/test_write_make_conf.py index fb84978..5d13bf5 100644 --- a/tests/test_write_make_conf.py +++ b/tests/test_write_make_conf.py @@ -12,31 +12,44 @@ from mirrorselect.output import Output class WriteMakeConfTestCase(unittest.TestCase): def test_write_make_conf(self): + def __do_it(var, mirror_string, make_conf, expected_result): + tempdir = tempfile.mkdtemp() + status_output = open(os.devnull, 'w') + #print("------make_conf--------", make_conf, "----------------------") + #print("*****expect*****\n", expected_result, "***********") + try: + config_path = os.path.join(tempdir, 'make.conf') + with open(config_path, 'wt') as f: + f.write(make_conf) + write_make_conf(Output(out=status_output), config_path, var, mirror_string) + with open(config_path, 'rt') as f: + result = f.read() + #print("!!!result!!!\n", result, "!!!!!!!!!!\n") + self.assertEqual(result, "{}".format(expected_result).format(mirror_string)) + finally: + shutil.rmtree(tempdir) + status_output.close() + var = 'GENTOO_MIRRORS' - mirror_string = '{}="a b"'.format(var) + mirrors = ( + ('{}="a"'.format(var)), + ('{}="a b"'.format(var)), + ('{}="a b c"'.format(var)), + ) cases = ( - ('{}="foo\nbar"\n'.format(var), '{}\n'.format(mirror_string)), - ('\n{}="foo\nbar"\n'.format(var), '\n{}\n'.format(mirror_string)), - ('\n{}="foo bar"\n'.format(var), '\n{}\n'.format(mirror_string)), - ('\n{}="foo bar"\n\n'.format(var), '\n\n{}\n'.format(mirror_string)), - ('\n{}="foo \\\nbar"\n'.format(var), '\n{}\n'.format(mirror_string)), - ('\n\n{}="foo \\\nbar"\n'.format(var), '\n\n{}\n'.format(mirror_string)), - ('\n\n{}="foo \\\nbar"\na="b"\n'.format(var), '\n\na="b"\n{}\n'.format(mirror_string)), - ('', '{}\n'.format(mirror_string)), + ('{}="foo\nbar"\n'.format(var), '{}\n'), + ('\n{}="foo\nbar"\n'.format(var), '\n{}\n'), + ('\n{}="foo bar"\n'.format(var), '\n{}\n'), + ('\n{}="foo bar"\n\n'.format(var), '\n\n{}\n'), + ('\n{}="foo \\\nbar"\n'.format(var), '\n{}\n'), + ('\n\n{}="foo \\\nbar"\n'.format(var), '\n\n{}\n'), + ('\n\n{}="foo \\\nbar"\na="b"\n'.format(var), '\n\na="b"\n{}\n'), + ('\n\n{}="foo \\\n bar"\na="b"\n'.format(var), '\n\na="b"\n{}\n'), + ('\n\n{}="foo \\\n bar\\\n baz"\na="b"\n'.format(var), '\n\na="b"\n{}\n'), + ('', '{}\n'), ) - for make_conf, expected_result in cases: - tempdir = tempfile.mkdtemp() - status_output = open(os.devnull, 'w') - try: - config_path = os.path.join(tempdir, 'make.conf') - with open(config_path, 'wt') as f: - f.write(make_conf) - write_make_conf(Output(out=status_output), config_path, var, mirror_string) - with open(config_path, 'rt') as f: - result = f.read() - self.assertEqual(result, expected_result) - finally: - shutil.rmtree(tempdir) - status_output.close() + for mirror in mirrors: + for make_conf, expected_result in cases: + __do_it(var, mirror, make_conf, expected_result) -- cgit v1.2.3-65-gdbad