From a86872d65332579e4bfad04de571350b64d2f0dd Mon Sep 17 00:00:00 2001 From: holger krekel Date: Sun, 25 Nov 2012 20:32:03 +0100 Subject: rtrim lines in generated file --- tests/test_quickstart.py | 73 ++++++++++++++++++++++++------------------------ tox/_quickstart.py | 21 +++++++++----- 2 files changed, 50 insertions(+), 44 deletions(-) diff --git a/tests/test_quickstart.py b/tests/test_quickstart.py index 13256df..64d8790 100644 --- a/tests/test_quickstart.py +++ b/tests/test_quickstart.py @@ -2,35 +2,34 @@ import pytest import tox._quickstart -@pytest.fixture() -def cleandir(tmpdir): - tmpdir.chdir() - -@pytest.mark.usefixtures("cleandir") class TestToxQuickstartMain(object): + @pytest.fixture(autouse=True) + def cleandir(self, tmpdir): + tmpdir.chdir() + def mock_term_input_return_values(self, return_values): for return_val in return_values: yield return_val - + def get_mock_term_input(self, return_values): generator = self.mock_term_input_return_values(return_values) - + def mock_term_input(prompt): try: return next(generator) except NameError: return generator.next() - + return mock_term_input def test_quickstart_main_choose_individual_pythons_and_pytest(self, monkeypatch): monkeypatch.setattr( - tox._quickstart, 'term_input', + tox._quickstart, 'term_input', self.get_mock_term_input(['4', 'Y', 'Y', 'Y', 'Y', 'N', 'N', 'Y', 'Y', 'Y', 'N', 'py.test', 'pytest'])) - + tox._quickstart.main(argv=['tox-quickstart']) - + expected_tox_ini = """ # Tox (http://tox.testrun.org/) is a tool for running tests # in multiple virtualenvs. This configuration file will run the @@ -42,15 +41,15 @@ envlist = py24, py25, py26, py27, py32, py33, pypy [testenv] commands = py.test -deps = +deps = pytest """.lstrip() result = open('tox.ini').read() assert(result == expected_tox_ini) - + def test_quickstart_main_choose_individual_pythons_and_nose_adds_deps(self, monkeypatch): monkeypatch.setattr( - tox._quickstart, 'term_input', + tox._quickstart, 'term_input', self.get_mock_term_input(['4', 'Y', 'Y', 'Y', 'Y', 'N', 'N', 'Y', 'Y', 'Y', 'N', 'nosetests', ''])) tox._quickstart.main(argv=['tox-quickstart']) @@ -66,7 +65,7 @@ envlist = py24, py25, py26, py27, py32, py33, pypy [testenv] commands = nosetests -deps = +deps = nose """.lstrip() result = open('tox.ini').read() @@ -74,7 +73,7 @@ deps = def test_quickstart_main_choose_individual_pythons_and_trial_adds_deps(self, monkeypatch): monkeypatch.setattr( - tox._quickstart, 'term_input', + tox._quickstart, 'term_input', self.get_mock_term_input(['4', 'Y', 'Y', 'Y', 'Y', 'N', 'N', 'Y', 'Y', 'Y', 'N', 'trial', ''])) tox._quickstart.main(argv=['tox-quickstart']) @@ -90,7 +89,7 @@ envlist = py24, py25, py26, py27, py32, py33, pypy [testenv] commands = trial -deps = +deps = twisted """.lstrip() result = open('tox.ini').read() @@ -98,7 +97,7 @@ deps = def test_quickstart_main_choose_individual_pythons_and_pytest_adds_deps(self, monkeypatch): monkeypatch.setattr( - tox._quickstart, 'term_input', + tox._quickstart, 'term_input', self.get_mock_term_input(['4', 'Y', 'Y', 'Y', 'Y', 'N', 'N', 'Y', 'Y', 'Y', 'N', 'py.test', ''])) tox._quickstart.main(argv=['tox-quickstart']) @@ -114,7 +113,7 @@ envlist = py24, py25, py26, py27, py32, py33, pypy [testenv] commands = py.test -deps = +deps = pytest """.lstrip() result = open('tox.ini').read() @@ -122,7 +121,7 @@ deps = def test_quickstart_main_choose_py27_and_pytest_adds_deps(self, monkeypatch): monkeypatch.setattr( - tox._quickstart, 'term_input', + tox._quickstart, 'term_input', self.get_mock_term_input(['1', 'py.test', ''])) tox._quickstart.main(argv=['tox-quickstart']) @@ -138,7 +137,7 @@ envlist = py27 [testenv] commands = py.test -deps = +deps = pytest """.lstrip() result = open('tox.ini').read() @@ -146,7 +145,7 @@ deps = def test_quickstart_main_choose_py27_and_py33_and_pytest_adds_deps(self, monkeypatch): monkeypatch.setattr( - tox._quickstart, 'term_input', + tox._quickstart, 'term_input', self.get_mock_term_input(['2', 'py.test', ''])) tox._quickstart.main(argv=['tox-quickstart']) @@ -162,7 +161,7 @@ envlist = py27, py33 [testenv] commands = py.test -deps = +deps = pytest """.lstrip() result = open('tox.ini').read() @@ -170,7 +169,7 @@ deps = def test_quickstart_main_choose_all_pythons_and_pytest_adds_deps(self, monkeypatch): monkeypatch.setattr( - tox._quickstart, 'term_input', + tox._quickstart, 'term_input', self.get_mock_term_input(['3', 'py.test', ''])) tox._quickstart.main(argv=['tox-quickstart']) @@ -186,7 +185,7 @@ envlist = py24, py25, py26, py27, py30, py31, py32, py33, pypy, jython [testenv] commands = py.test -deps = +deps = pytest """.lstrip() result = open('tox.ini').read() @@ -194,7 +193,7 @@ deps = def test_quickstart_main_choose_individual_pythons_and_defaults(self, monkeypatch): monkeypatch.setattr( - tox._quickstart, 'term_input', + tox._quickstart, 'term_input', self.get_mock_term_input(['4', '', '', '', '', '', '', '', '', '', '', '', ''])) tox._quickstart.main(argv=['tox-quickstart']) @@ -210,8 +209,8 @@ envlist = py24, py25, py26, py27, py30, py31, py32, py33, pypy, jython [testenv] commands = {envpython} setup.py test -deps = - +deps = + """.lstrip() result = open('tox.ini').read() assert(result == expected_tox_ini) @@ -222,9 +221,9 @@ deps = f.write('foo bar\n') finally: f.close() - + monkeypatch.setattr( - tox._quickstart, 'term_input', + tox._quickstart, 'term_input', self.get_mock_term_input(['4', '', '', '', '', '', '', '', '', '', '', '', '', ''])) tox._quickstart.main(argv=['tox-quickstart']) @@ -240,8 +239,8 @@ envlist = py24, py25, py26, py27, py30, py31, py32, py33, pypy, jython [testenv] commands = {envpython} setup.py test -deps = - +deps = + """.lstrip() result = open('tox-generated.ini').read() assert(result == expected_tox_ini) @@ -271,7 +270,7 @@ envlist = py24, py25, py26, py27, py32, py33, pypy [testenv] commands = py.test -deps = +deps = pytest """.lstrip() d = tox._quickstart.process_input(d) @@ -298,8 +297,8 @@ envlist = py26, py27 [testenv] commands = python setup.py test -deps = - +deps = + """.lstrip() d = tox._quickstart.process_input(d) tox._quickstart.generate(d) @@ -324,7 +323,7 @@ envlist = py27 [testenv] commands = trial -deps = +deps = Twisted """.lstrip() d = tox._quickstart.process_input(d) @@ -353,7 +352,7 @@ envlist = py27, py32, py33, pypy [testenv] commands = nosetests -v -deps = +deps = nose """.lstrip() d = tox._quickstart.process_input(d) diff --git a/tox/_quickstart.py b/tox/_quickstart.py index 6845ac8..4b39d04 100644 --- a/tox/_quickstart.py +++ b/tox/_quickstart.py @@ -151,16 +151,16 @@ Please enter values for the following settings (just press Enter to accept a default value, if one is given in brackets).''') sys.stdout.write('\n') - + print(''' What Python versions do you want to test against? Choices: [1] py27 [2] py27, py33 [3] (All versions) %s [4] Choose each one-by-one''' % ', '.join(all_envs)) - do_prompt(d, 'canned_pyenvs', 'Enter the number of your choice', + do_prompt(d, 'canned_pyenvs', 'Enter the number of your choice', '3', choice('1', '2', '3', '4')) - + if d['canned_pyenvs'] == '1': d['py27'] = True elif d['canned_pyenvs'] == '2': @@ -189,7 +189,7 @@ What command should be used to test your project -- examples: default_deps = 'nose' if 'trial' in d['commands']: default_deps = 'twisted' - + print(''' What dependencies does your project have?''') do_prompt(d, 'deps', 'Comma-separated list of dependencies', default_deps) @@ -197,15 +197,22 @@ What dependencies does your project have?''') def process_input(d): d['envlist'] = ', '.join([env for env in all_envs if d.get(env) is True]) - d['deps'] = '\n' + '\n'.join([' %s' % dep.strip() for dep in d['deps'].split(',')]) + d['deps'] = '\n' + '\n'.join([' %s' % dep.strip() + for dep in d['deps'].split(',')]) return d +def rtrim_right(text): + lines = [] + for line in text.split("\n"): + lines.append(line.rstrip()) + return "\n".join(lines) def generate(d, overwrite=True, silent=False): """Generate project based on values in *d*.""" conf_text = QUICKSTART_CONF % d + conf_text = rtrim_right(conf_text) def write_file(fpath, mode, content): print('Creating file %s.' % fpath) @@ -216,14 +223,14 @@ def generate(d, overwrite=True, silent=False): f.close() sys.stdout.write('\n') - + fpath = 'tox.ini' if path.isfile(fpath) and not overwrite: print('File %s already exists.' % fpath) do_prompt(d, 'fpath', 'Alternative path to write tox.ini contents to', 'tox-generated.ini') fpath = d['fpath'] - + write_file(fpath, 'w', conf_text) if silent: -- cgit v1.2.1