Commits

holger krekel committed dc560a7

rtrim lines in generated file

Comments (0)

Files changed (2)

tests/test_quickstart.py

 import tox._quickstart
 
 
-@pytest.fixture()
-def cleandir(tmpdir):
-    tmpdir.chdir()
 
+class TestToxQuickstartMain(object):
+    @pytest.fixture(autouse=True)
+    def cleandir(self, tmpdir):
+        tmpdir.chdir()
 
-@pytest.mark.usefixtures("cleandir")
-class TestToxQuickstartMain(object):
     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
 
 [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'])
 
 [testenv]
 commands = nosetests
-deps = 
+deps =
     nose
 """.lstrip()
         result = open('tox.ini').read()
 
     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'])
 
 [testenv]
 commands = trial
-deps = 
+deps =
     twisted
 """.lstrip()
         result = open('tox.ini').read()
 
     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'])
 
 [testenv]
 commands = py.test
-deps = 
+deps =
     pytest
 """.lstrip()
         result = open('tox.ini').read()
 
     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'])
 
 [testenv]
 commands = py.test
-deps = 
+deps =
     pytest
 """.lstrip()
         result = open('tox.ini').read()
 
     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'])
 
 [testenv]
 commands = py.test
-deps = 
+deps =
     pytest
 """.lstrip()
         result = open('tox.ini').read()
 
     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'])
 
 [testenv]
 commands = py.test
-deps = 
+deps =
     pytest
 """.lstrip()
         result = open('tox.ini').read()
 
     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'])
 
 [testenv]
 commands = {envpython} setup.py test
-deps = 
-    
+deps =
+
 """.lstrip()
         result = open('tox.ini').read()
         assert(result == expected_tox_ini)
             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'])
 
 [testenv]
 commands = {envpython} setup.py test
-deps = 
-    
+deps =
+
 """.lstrip()
         result = open('tox-generated.ini').read()
         assert(result == expected_tox_ini)
 
 [testenv]
 commands = py.test
-deps = 
+deps =
     pytest
 """.lstrip()
         d = tox._quickstart.process_input(d)
 
 [testenv]
 commands = python setup.py test
-deps = 
-    
+deps =
+
 """.lstrip()
         d = tox._quickstart.process_input(d)
         tox._quickstart.generate(d)
 
 [testenv]
 commands = trial
-deps = 
+deps =
     Twisted
 """.lstrip()
         d = tox._quickstart.process_input(d)
 
 [testenv]
 commands = nosetests -v
-deps = 
+deps =
     nose
 """.lstrip()
         d = tox._quickstart.process_input(d)

tox/_quickstart.py

 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':
         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)
 
 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)
             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: