Anonymous avatar Anonymous committed 4414956

issue_1_empty_setup_py: fix for issue #1: Empty setup.py leads to very obscure error

This was caused by no dist directory being created and listing
that directory raising an exception.

- added some test for setup.py:
- empty
- only start of line comment
- some code, but no setup()
- on error finding the dist
- check if empty or comment only setup.py: msg that setup.py is empty
- msg to check 'python setup.py sdist' by hand

Comments (0)

Files changed (2)

tests/test_z_cmdline.py

     result = cmd.run("tox", )
     assert result.ret == 0
 
+def test_minimal_setup_py_empty(cmd, initproj):
+    initproj("pkg123-0.7", filedefs={
+        'tests': {'test_hello.py': "def test_hello(): pass"},
+        'setup.py': """
+        """
+        ,
+        'tox.ini': ''
+
+    })
+    result = cmd.run("tox", )
+    assert result.ret == 1
+    result.stdout.fnmatch_lines([
+        "*ERROR*empty*",
+    ])
+
+def test_minimal_setup_py_comment_only(cmd, initproj):
+    initproj("pkg123-0.7", filedefs={
+        'tests': {'test_hello.py': "def test_hello(): pass"},
+        'setup.py': """\n# some comment
+
+        """
+        ,
+        'tox.ini': ''
+
+    })
+    result = cmd.run("tox", )
+    assert result.ret == 1
+    result.stdout.fnmatch_lines([
+        "*ERROR*empty*",
+    ])
+
+def test_minimal_setup_py_non_functional(cmd, initproj):
+    initproj("pkg123-0.7", filedefs={
+        'tests': {'test_hello.py': "def test_hello(): pass"},
+        'setup.py': """
+        import sys
+
+        """
+        ,
+        'tox.ini': ''
+
+    })
+    result = cmd.run("tox", )
+    assert result.ret == 1
+    result.stdout.fnmatch_lines([
+        "*ERROR*check setup.py*",
+    ])
+
 def test_sdist_fails(cmd, initproj):
     initproj("pkg123-0.7", filedefs={
         'tests': {'test_hello.py': "def test_hello(): pass"},
             action.popen([sys.executable, setup, "sdist", "--formats=zip",
                           "--dist-dir", self.config.distdir, ],
                           cwd=self.config.setupdir)
-            return self.config.distdir.listdir()[0]
+            try:
+                return self.config.distdir.listdir()[0]
+            except py.error.ENOENT:
+                # check if empty or comment only
+                data = []
+                with open(str(setup)) as fp:
+                    for line in fp:
+                        if line and line[0] == '#':
+                            continue
+                        data.append(line)
+                if not ''.join(data).strip():
+                    self.report.error(
+                        'setup.py is empty'
+                    )
+                    raise SystemExit(1)
+                self.report.error(
+                    'No dist directory found. Please check setup.py, e.g with:\n'\
+                    '     python setup.py sdist'
+                    )
+                raise SystemExit(1)
+
 
     def make_emptydir(self, path):
         if path.check():
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.