Skip to content

Commit

Permalink
make sure that the tests are actually executed in tox with Python 2.7
Browse files Browse the repository at this point in the history
  • Loading branch information
ntamas committed Apr 27, 2020
1 parent a7752c1 commit 6a82d8a
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 6 deletions.
3 changes: 3 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,9 @@ def use_educated_guess(self):
},
)

if sys.version_info <= (2, 7):
options["requires"] = options.pop("install_requires")

if sys.version_info > (3, 0):
options["use_2to3"] = True

Expand Down
7 changes: 5 additions & 2 deletions src/_igraph/attributes.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,11 @@ int igraphmodule_i_attribute_struct_index_vertex_names(
PyErr_Format(
PyExc_RuntimeError,
"error while indexing vertex names; did you accidentally try to "
"use a non-hashable object as a vertex name earlier? "
"Check the name of vertex %R (%R)", value, key
"use a non-hashable object as a vertex name earlier?"
#ifdef IGRAPH_PYTHON3
/* %R is not supported in Python 2.x */
" Check the name of vertex %R (%R)", value, key
#endif
);
}

Expand Down
4 changes: 3 additions & 1 deletion tests/test_attributes.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# vim:ts=4 sw=4 sts=4:
import sys
import unittest
from igraph import *

Expand Down Expand Up @@ -102,7 +103,8 @@ def testUnhashableVertexNames(self):

# Check the exception
self.assertTrue(isinstance(err, RuntimeError))
self.assertTrue(repr(value) in str(err))
if sys.version_info >= (3, 4):
self.assertTrue(repr(value) in str(err))

def testVertexNameIndexingBug196(self):
g = Graph()
Expand Down
2 changes: 1 addition & 1 deletion tests/test_foreign.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def testPickle(self):
pickle = bytes(pickle)
else:
pickle = "".join(map(chr, pickle))
with temporary_file(pickle, "wb") as tmpfname:
with temporary_file(pickle, "wb", binary=True) as tmpfname:
g = Graph.Read_Pickle(pickle)
self.assertTrue(isinstance(g, Graph))
self.assertTrue(g.vcount() == 3 and g.ecount() == 1 and
Expand Down
4 changes: 2 additions & 2 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def skipIf(condition, reason):


@contextmanager
def temporary_file(content=None, mode=None):
def temporary_file(content=None, mode=None, binary=False):
tmpf, tmpfname = tempfile.mkstemp()
os.close(tmpf)

Expand All @@ -59,7 +59,7 @@ def temporary_file(content=None, mode=None):

tmpf = open(tmpfname, mode)
if content is not None:
if hasattr(content, "encode"):
if hasattr(content, "encode") and not binary:
tmpf.write(dedent(content).encode("utf8"))
else:
tmpf.write(content)
Expand Down
3 changes: 3 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ deps =
setenv =
TESTING_IN_TOX=1

[testenv:py27]
commands = python -m unittest discover

[flake8]
max-line-length = 80
select = C,E,F,W,B,B950
Expand Down

0 comments on commit 6a82d8a

Please sign in to comment.