From 6a82d8ace7dfbcfe4d51b1d5826bf9fd92d2949e Mon Sep 17 00:00:00 2001 From: Tamas Nepusz Date: Mon, 27 Apr 2020 18:05:39 +0200 Subject: [PATCH] make sure that the tests are actually executed in tox with Python 2.7 --- setup.py | 3 +++ src/_igraph/attributes.c | 7 +++++-- tests/test_attributes.py | 4 +++- tests/test_foreign.py | 2 +- tests/utils.py | 4 ++-- tox.ini | 3 +++ 6 files changed, 17 insertions(+), 6 deletions(-) diff --git a/setup.py b/setup.py index 29482e21d..98465b559 100644 --- a/setup.py +++ b/setup.py @@ -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 diff --git a/src/_igraph/attributes.c b/src/_igraph/attributes.c index fd9431834..db746334c 100644 --- a/src/_igraph/attributes.c +++ b/src/_igraph/attributes.c @@ -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 ); } diff --git a/tests/test_attributes.py b/tests/test_attributes.py index 45984a737..4d81ee18f 100644 --- a/tests/test_attributes.py +++ b/tests/test_attributes.py @@ -1,4 +1,5 @@ # vim:ts=4 sw=4 sts=4: +import sys import unittest from igraph import * @@ -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() diff --git a/tests/test_foreign.py b/tests/test_foreign.py index 5c4ff1d30..ff30ec2af 100644 --- a/tests/test_foreign.py +++ b/tests/test_foreign.py @@ -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 diff --git a/tests/utils.py b/tests/utils.py index c4fab472f..82b951a54 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -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) @@ -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) diff --git a/tox.ini b/tox.ini index 37d5c3e86..d2c11f3e3 100644 --- a/tox.ini +++ b/tox.ini @@ -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