Closed OrkoHunter closed 9 years ago
msg = unicode(tmp.read(), sys.stdout.encoding)
How about str(tmp.read(), 'ascii')
?
How about str(tmp.read(), 'ascii')?
str()
does not take two arguments. Can't we use decode()
or encode()
functions here?
decode()
is the right choice.
And so, it works! :)
We need to update the directory structure of the existing files in the master
. Should I add one commit here and change the name of PR or make a separate one after this goes in?
Make a separate PR.
That would be possible after this goes in, to avoid merge conflicts.
Are you able to test this PR?
@ysitu Yes, and it works. I have a local setup which does not uses the namespace packing for installation. So, I test the changes there manually.
Regarding the automated script and Travis CI, that'd be working as soon as the namespace installation starts working for networkx-metis
, which seems to be a little brainstorming for me.
Do you mean that you have a test case that forces METIS to generate an error message, and you can verify that the error message is correctly captured?
I have fetched all the files from the current master plus files currently split into three PRs (#3 #4 #14), at one place, in one test directory and then I run
$ python setup.py build_clib
followed by
$ python setup.py build_ext --inplace
And for this particular PR, I run nosetests
which verify the tests written under tests/test_metis.py
and then I manually try partitioning a graph by importing networkx
.
In the current situation, after this PR
$ nosetests [master] 10:52:53
....
----------------------------------------------------------------------
Ran 4 tests in 0.096s
OK
Those test cases do not really exercise the code paths that deal with exceptions.
But those tests were failing before this patch. They pass now.
The tests passing does not mean that any output from METIS is correctly captured. We need to make sure that we relay some meaningful error messages to the user when something goes wrong.
We need to make sure that we relay some meaningful error messages to the user when something goes wrong.
That means more test cases.
What are some possible situations when things would go wrong? Partitioning directed
or multi
graphs are covered, nparts > 0
covered, what more could possibly go wrong? We might need another PR for tests
. As much as I understand, the problem of StringIO instance of std.stdout
is covered, which is why this PR was created.
I think that you can put some invalid values into MetisOptions
, e.g., niter <= 0
. In options.c
there is a CheckParams
function. You can find the expected error message there.
Does that mean adding something like test_MetisOptions
in test_metis.py
?
diff --git a/tests/test_metis.py b/tests/test_metis.py
index 337477d..a50a691 100644
--- a/tests/test_metis.py
+++ b/tests/test_metis.py
@@ -2,7 +2,7 @@ import itertools
import nose.tools
import _metis
-
+import _types
def make_cycle(n):
xadj = list(range(0, 2 * n + 1, 2))
@@ -68,3 +68,10 @@ class TestMetis(object):
sorted(map(sorted,
[[(sep[0] + i) % n for i in range(1, n // 2)],
[(sep[1] + i) % n for i in range(1, n // 2)]])))
+
+ def test_MetisOptions(self):
+ n = 16
+ xadj, adjncy = make_cycle(n)
+ objval, part = _metis.part_graph(
+ xadj, adjncy, 2, options=_types.MetisOptions)
+
...followed by assertions of errors listed in CheckParams
of options.c
I don't have much idea about using options
in part_graph
and other functions.
You create a MetisOptions
object and set its niter
property to a negative value.
Simply this?
def test_MetisOptions(self):
options = _types.MetisOptions
options.niter = -1
How should I invoke MetisOptions in the functions like part_graph
?
Well, we should be doing this over #3.
You should do
n = 16
xadj, adjncy = make_cycle(n)
options = types.MetisOptions()
options.niter = -1
assert_raises_regexp(MetisError, '<error message regex>',
_metis.part_graph, xadj, adjncy, 2, options=options)
For the following,
def test_MetisOptions(self):
n = 16
xadj, adjncy = make_cycle(n)
options = _types.MetisOptions()
options.niter = -1
nose.tools.assert_raises_regexp(_types.MetisError, 'Input Error: Incorrect niter.',
_metis.part_graph, xadj, adjncy, 2, options=options)
I get
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/nose/case.py", line 197, in runTest
self.test(*self.arg)
File "/home/hunter/GSoC/2015/test/tests/test_metis.py", line 78, in test_MetisOptions
_metis.part_graph, xadj, adjncy, 2, options=options)
AssertionError: MetisError not raised
Was an exception raised at all?
I guess no. It's independent of the error string 'Input Error: Incorrect niter.'
Error is raised if niter < -1. This one passes the test and the MetisError is being raised in it.
def test_MetisOptions(self):
n = 16
xadj, adjncy = make_cycle(n)
options = _types.MetisOptions(niter=-2)
nose.tools.assert_raises_regexp(_types.MetisError, 'Input Error: Incorrect niter.',
_metis.part_graph, xadj, adjncy, 2, options=options)
Rebased branch. PR updated with
_types
in _metis.pyx
Fixes errors concerning StringIO instance of
sys.stdout
.@ysitu This line
needs to be changed too.