Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 543814 | Differences between
and this patch

Collapse All | Expand All

(-)a/.gitignore (-1 lines)
Lines 1-6 Link Here
1
*.py[co]
1
*.py[co]
2
testing*
2
testing*
3
test*
4
*.geany
3
*.geany
5
build*
4
build*
6
.gitignore
5
.gitignore
(-)a/mirrorselect/configs.py (-6 / +27 lines)
Lines 4-10 Link Here
4
"""Mirrorselect 2.x
4
"""Mirrorselect 2.x
5
 Tool for selecting Gentoo source and rsync mirrors.
5
 Tool for selecting Gentoo source and rsync mirrors.
6
6
7
Copyright 2005-2012 Gentoo Foundation
7
Copyright 2005-2019 Gentoo Authors
8
8
9
	Copyright (C) 2005 Colin Kingsley <tercel@gentoo.org>
9
	Copyright (C) 2005 Colin Kingsley <tercel@gentoo.org>
10
	Copyright (C) 2008 Zac Medico <zmedico@gentoo.org>
10
	Copyright (C) 2008 Zac Medico <zmedico@gentoo.org>
Lines 75-84 def write_make_conf(output, config_path, var, mirror_string): Link Here
75
	except IOError:
75
	except IOError:
76
		lines = []
76
		lines = []
77
77
78
	regex = re.compile('^%s=.*' % var)
78
	with open(config_path + '.backup', 'r') as f:
79
	for line in lines:
79
		lex = shlex.shlex(f, posix=True)
80
		if regex.match(line):
80
		lex.wordchars = string.digits + letters + r"~!@#$%*_\:;?,./-+{}"
81
			lines.remove(line)
81
		lex.quotes = "\"'"
82
		while True:
83
			key = lex.get_token()
84
85
			if key == var:
86
				begin_line = lex.lineno
87
				equ = lex.get_token()
88
				if equ is None:
89
					break
90
				if equ != '=':
91
					continue
92
93
				val = lex.get_token()
94
				if val is None:
95
					break
96
				end_line = lex.lineno
97
98
				new_lines = []
99
				for index, line in enumerate(lines):
100
					if index < begin_line - 1 or index >= end_line - 1:
101
						new_lines.append(line)
102
				lines = new_lines
103
				break
82
104
83
	lines.append(mirror_string)
105
	lines.append(mirror_string)
84
106
Lines 92-98 def write_make_conf(output, config_path, var, mirror_string): Link Here
92
	config.close()
114
	config.close()
93
115
94
	output.print_info('Done.\n')
116
	output.print_info('Done.\n')
95
	sys.exit(0)
96
117
97
118
98
def write_repos_conf(output, config_path, var, value):
119
def write_repos_conf(output, config_path, var, value):
(-)a/setup.py (-19 / +18 lines)
Lines 8-16 import re Link Here
8
import sys
8
import sys
9
from distutils import core, log
9
from distutils import core, log
10
from distutils.command.sdist import sdist
10
from distutils.command.sdist import sdist
11
from distutils.core import Command
11
12
12
import os
13
import os
13
import io
14
import io
15
import unittest
14
16
15
17
16
__version__ = os.getenv('VERSION', default=os.getenv('PVR', default='9999'))
18
__version__ = os.getenv('VERSION', default=os.getenv('PVR', default='9999'))
Lines 80-105 class x_sdist(sdist): Link Here
80
		sdist.finalize_options(self)
82
		sdist.finalize_options(self)
81
83
82
84
83
def	load_test():
85
class TestCommand(Command):
84
	"""Only return the real test class if it's actually being run so that we
86
	user_options = []
85
	don't depend on snakeoil just to install."""
86
87
87
	desc = "run the test suite"
88
	def initialize_options(self):
88
	if 'test' in sys.argv[1:]:
89
		pass
89
		try:
90
90
			from snakeoil import distutils_extensions
91
	def finalize_options(self):
91
		except ImportError:
92
		pass
92
			sys.stderr.write("Error: We depend on dev-python/snakeoil ")
93
93
			sys.stderr.write("to run tests.\n")
94
	def run(self):
94
			sys.exit(1)
95
		suite = unittest.TestSuite()
95
		class test(distutils_extensions.test):
96
		tests = unittest.defaultTestLoader.discover('tests')
96
			description = desc
97
		suite.addTests(tests)
97
			default_test_namespace = 'mirrorselect.test'
98
		result = unittest.TextTestRunner(verbosity=2).run(suite)
98
	else:
99
		if result.errors or result.failures:
99
		class test(core.Command):
100
			raise SystemExit(1)
100
			description = desc
101
101
102
	return test
103
102
104
test_data = {
103
test_data = {
105
	'mirrorselect': [
104
	'mirrorselect': [
Lines 125-131 core.setup( Link Here
125
		['mirrorselect.8']),
124
		['mirrorselect.8']),
126
	),
125
	),
127
	cmdclass={
126
	cmdclass={
128
		'test': load_test(),
127
		'test': TestCommand,
129
		'sdist': x_sdist,
128
		'sdist': x_sdist,
130
		'set_version': set_version,
129
		'set_version': set_version,
131
	},
130
	},
(-)a/tests/test_write_make_conf.py (-1 / +41 lines)
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()

Return to bug 543814