public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] proj/mirrorselect:master commit in: mirrorselect/, tests/
@ 2022-05-31 18:39 Brian Dolbec
  0 siblings, 0 replies; only message in thread
From: Brian Dolbec @ 2022-05-31 18:39 UTC (permalink / raw
  To: gentoo-commits

commit:     a09b4d302e4cee79254d3ff4a5ac9f080b958acf
Author:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Tue May 31 17:58:14 2022 +0000
Commit:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Tue May 31 17:58:14 2022 +0000
URL:        https://gitweb.gentoo.org/proj/mirrorselect.git/commit/?id=a09b4d30

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 <dolsen <AT> gentoo.org>

 mirrorselect/main.py          |  2 +-
 tests/test_write_make_conf.py | 59 ++++++++++++++++++++++++++-----------------
 2 files changed, 37 insertions(+), 24 deletions(-)

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)


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2022-05-31 18:39 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-05-31 18:39 [gentoo-commits] proj/mirrorselect:master commit in: mirrorselect/, tests/ Brian Dolbec

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox