Permalink
Browse files

fix small client bugs + tests

  • Loading branch information...
1 parent 194772e commit 5e3faa67f8c05c9ba9b662ae499fe057928c98f5 @minrk minrk committed Mar 14, 2011
Showing with 28 additions and 3 deletions.
  1. +6 −3 IPython/zmq/parallel/client.py
  2. +22 −0 IPython/zmq/parallel/tests/test_client.py
@@ -378,7 +378,8 @@ def _setup_cluster_dir(self, profile, cluster_dir, ipython_dir):
def ids(self):
"""Always up-to-date ids property."""
self._flush_notifications()
- return self._ids
+ # always copy:
+ return list(self._ids)
def close(self):
if self._closed:
@@ -878,8 +879,10 @@ def run(self, filename, targets='all', block=None):
default: self.block
"""
- with open(filename, 'rb') as f:
- code = f.read()
+ with open(filename, 'r') as f:
+ # add newline in case of trailing indented whitespace
+ # which will cause SyntaxError
+ code = f.read()+'\n'
return self.execute(code, targets=targets, block=block)
def _maybe_raise(self, result):
@@ -1,4 +1,5 @@
import time
+from tempfile import mktemp
import nose.tools as nt
@@ -162,4 +163,25 @@ def test_get_result(self):
self.assertEquals(ahr.get(), ar.get())
ar2 = self.client.get_result(ar.msg_ids)
self.assertFalse(isinstance(ar2, AsyncHubResult))
+
+ def test_ids_list(self):
+ """test client.ids"""
+ self.add_engines(2)
+ ids = self.client.ids
+ self.assertEquals(ids, self.client._ids)
+ self.assertFalse(ids is self.client._ids)
+ ids.remove(ids[-1])
+ self.assertNotEquals(ids, self.client._ids)
+
+ def test_arun_newline(self):
+ """test that run appends newline to files"""
+ tmpfile = mktemp()
+ with open(tmpfile, 'w') as f:
+ f.write("""def g():
+ return 5
+ """)
+ v = self.client[-1]
+ v.run(tmpfile, block=True)
+ self.assertEquals(v.apply_sync_bound(lambda : g()), 5)
+

0 comments on commit 5e3faa6

Please sign in to comment.