Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tests for 2.7 #31

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ pycscope.files
pycscope.out
dist
pycscope.egg-info
.ropeproject/
*.pyc
.ropeproject/
16 changes: 16 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
language: python
python:
- "2.6"
- "2.7"
- "pypy"
- "pypy3"
- "3.2"
- "3.3"
- "3.4"
- "3.5"
- "3.5-dev" # 3.5 development branch
- "nightly" # currently points to 3.6-dev
# command to install dependencies
install: "pip install -r requirements-test.txt"
# command to run tests
script: ./runtests
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
```
========
PyCscope
========

:Copyright: Copyright 2013 Peter Portante. See LICENSE for details.
:Author: Peter Portante
:Release: 1.2.1
:Date: 2013/03/16
:Release: 1.2.2
:Date: 2017/03/30

Purpose
-------
Expand Down Expand Up @@ -96,11 +97,13 @@ by the `CscopeFinder` plugin for jEdit. Other editors are not tested.
Release Notes
-------------

This is PyCscope release 1.2.1
This is PyCscope release 1.2.2

========== ========= ====== ====================================================
Date Release Trac Changes
========== ========= ====== ====================================================
2017/03/30 1.2.2 N/A Fix Travis tests for 2.6 other testing issues.
---------- --------- ------ ----------------------------------------------------
2013/03/16 1.2.1 N/A Fix strings-as-symbols support (really).
---------- --------- ------ ----------------------------------------------------
2013/03/16 1.2 N/A Fix strings-as-symbols support; fix end of function
Expand Down Expand Up @@ -192,3 +195,4 @@ Date Release Trac Changes

#6 Create project space.
========== ========= ====== ====================================================
```
23 changes: 10 additions & 13 deletions pycscope/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@
-f reffile Use 'reffile' as cross-ref file name instead of 'cscope.out'
-i srclistfile Use the contents of 'srclistfile' as the list of source files to scan"""

import getopt, sys, os, string, re
import getopt, sys, os, re
import keyword, parser, symbol, token
import tokenize


class Mark(object):
Expand Down Expand Up @@ -117,7 +118,8 @@ def main(argv=None):
if o == "-f":
indexfn = a
if o == "-i":
args.extend(list(map(string.rstrip, open(a, 'r').readlines())))
with open(a) as f:
args.extend(x.rstrip() for x in f)

# Search current dir by default
if len(args) == 0:
Expand Down Expand Up @@ -148,7 +150,7 @@ def writeIndex(basepath, fout, indexbuff, fnamesbuff):
"""
# Write the header and index
index = ''.join(indexbuff)
index_len = len(index)
index_len = len(index.encode() if isinstance(u'' , str) else index)
hdr_len = len(basepath) + 25
fout.write("cscope 15 %s -c %010d" % (basepath, hdr_len + index_len))
fout.write(index)
Expand All @@ -175,7 +177,8 @@ def work(basepath, gen, debug):
indexbuff_len = parseFile(basepath, fname, indexbuff, indexbuff_len, fnamesbuff, dump=debug)
except (SyntaxError, AssertionError) as e:
print("pycscope.py: %s: Line %s: %s" % (e.filename, e.lineno, e))
pass
except Exception as e:
print("pycscope.py: %s: %s" % (fname, e))

return indexbuff, fnamesbuff

Expand Down Expand Up @@ -221,15 +224,9 @@ def parseFile(basepath, relpath, indexbuff, indexbuff_len, fnamesbuff, dump=Fals
"""
# Open the file and get the contents
fullpath = os.path.join(basepath, relpath)
try:
f = open(fullpath, 'rU')
except IOError as e:
# Can't open a file, emit message and ignore
print("pycscope.py: %s" % e)
return indexbuff_len
filecontents = f.read()
f.close()

bestopen = getattr(tokenize, 'open', open)
with bestopen(fullpath) as f:
filecontents = f.read()
# Add the file mark to the index
fnamesbuff.append(relpath)
indexbuff.append("\n%s%s\n\n" % (Mark(Mark.FILE), relpath))
Expand Down
2 changes: 2 additions & 0 deletions requirements-test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
coverage==4.0
nose==1.3.7
2 changes: 1 addition & 1 deletion test/testgenfiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ def testgenfiles(self,):

# Actual test
fs = list(pycscope.genFiles(tmpd, ['a.py', 'b', "s"], True))
self.assertEquals(fs, ['a.py', 's/t/f.py', 's/t/e.py', 's/d.py', 's/c.py'])
self.assertEquals(sorted(fs), sorted(['a.py', 's/t/f.py', 's/t/e.py', 's/d.py', 's/c.py']))
finally:
shutil.rmtree(tmpd)
2 changes: 1 addition & 1 deletion test/testimports.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def setUp(self,):
self.maxDiff = None

def testimports(self,):
cwd = os.getcwd()
cwd = os.path.dirname(__file__)
fn = "imports.py"
l = pycscope.parseFile(cwd, fn, self.buf, 0, self.fnbuf)
self.assertEqual(l, len(self.buf))
Expand Down
2 changes: 1 addition & 1 deletion test/testissues.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def test0018(self,):
""" Make sure two newlines occur after a file mark
when the source file starts with non-symbol text.
"""
cwd = os.getcwd()
cwd = os.path.dirname(__file__)
fn = "issue0018.py"
l = pycscope.parseFile(cwd, fn, self.buf, 0, self.fnbuf)
self.assertEqual(l, len(self.buf))
Expand Down
8 changes: 4 additions & 4 deletions test/testparsefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ def setUp(self,):
self.maxDiff = None

def testioerrors(self,):
cwd = os.getcwd()
cwd = os.path.dirname(__file__)
fn = "_does_not_exist_.py"
l = pycscope.parseFile(cwd, fn, self.buf, 0, self.fnbuf)
self.assertEqual(l, 0)
with self.assertRaises(IOError):
pycscope.parseFile(cwd, fn, self.buf, 0, self.fnbuf)

def testbadsyntax(self,):
cwd = os.getcwd()
cwd = os.path.dirname(__file__)
fn = "badsyntax.py"
try:
l = pycscope.parseFile(cwd, fn, self.buf, 0, self.fnbuf)
Expand Down