Skip to content
Browse files

Don't use print

  • Loading branch information...
1 parent ca0de7d commit 533a336b206e7f277038fad6bf4adf1575e08a0f @chrisrossi chrisrossi committed Sep 13, 2012
Showing with 28 additions and 22 deletions.
  1. +4 −3 acidfs/__init__.py
  2. +24 −19 acidfs/tests.py
View
7 acidfs/__init__.py
@@ -5,7 +5,6 @@
import os
import shutil
import subprocess
-import sys
import tempfile
import traceback
import transaction
@@ -498,7 +497,8 @@ def tpc_finish(self, tx):
# file directly.
reffile = os.path.join(self.db, 'refs', 'heads', self.head)
with open(reffile, 'w') as f:
- print >> f, self.next_commit
+ f.write(self.next_commit)
+ f.write('\n')
self.close()
@@ -858,7 +858,8 @@ def save(self):
stdin=subprocess.PIPE, stdout=subprocess.PIPE) as proc:
for name, (type, oid, obj) in self.contents.items():
mode = '100644' if type == 'blob' else '040000'
- print >> proc.stdin, '%s %s %s\t%s' % (mode, type, oid, name)
+ proc.stdin.write('%s %s %s\t%s' % (mode, type, oid, name))
+ proc.stdin.write('\n')
proc.stdin.close()
oid = proc.stdout.read().strip()
return oid
View
43 acidfs/tests.py
@@ -91,7 +91,7 @@ def test_read_write_file(self):
fs = self.make_one()
with fs.open('foo', 'w') as f:
self.assertTrue(f.writable())
- print >> f, b'Hello'
+ fprint(f, b'Hello')
with self.assertNoSuchFileOrDirectory('foo'):
fs.open('foo')
self.assertEqual(fs.open('foo').read(), b'Hello\n')
@@ -111,7 +111,7 @@ def test_read_write_file_in_subfolder(self):
fs.mkdir('foo')
self.assertTrue(fs.isdir('foo'))
with fs.open('foo/bar', 'w') as f:
- print >> f, b'Hello'
+ fprint(f, b'Hello')
with fs.open('foo/bar') as f:
self.assertEqual(f.read(), b'Hello\n')
actual_file = os.path.join(self.tmp, 'foo', 'bar')
@@ -130,7 +130,7 @@ def test_read_write_file_in_subfolder_bare_repo(self):
fs.mkdir('foo')
self.assertTrue(fs.isdir('foo'))
with fs.open('foo/bar', 'w') as f:
- print >> f, b'Hello'
+ fprint(f, b'Hello')
with fs.open('foo/bar') as f:
self.assertEqual(f.read(), b'Hello\n')
transaction.commit()
@@ -168,7 +168,7 @@ def test_open_edge_cases(self):
fs.open('foo', 'wtf')
with fs.open('bar', 'w') as f:
- print >> f, b'Howdy!'
+ fprint(f, b'Howdy!')
with self.assertRaises(ValueError) as cm:
transaction.commit()
self.assertEqual(str(cm.exception),
@@ -218,12 +218,12 @@ def test_commit_metadata_extended_info_for_user(self):
def test_modify_file(self):
fs = self.make_one()
with fs.open('foo', 'w') as f:
- print >> f, b"Howdy!"
+ fprint(f, b"Howdy!")
transaction.commit()
path = os.path.join(self.tmp, 'foo')
with fs.open('foo', 'w') as f:
- print >> f, b"Hello!"
+ fprint(f, b"Hello!")
self.assertEqual(fs.open('foo').read(), b'Howdy!\n')
self.assertEqual(fs.open('foo').read(), b'Hello!\n')
self.assertEqual(open(path).read(), b'Howdy!\n')
@@ -236,7 +236,7 @@ def test_error_writing_blob(self):
with self.assertRaises(subprocess.CalledProcessError):
with fs.open('foo', 'w') as f:
shutil.rmtree(os.path.join(self.tmp, '.git'))
- print >> f, b'Howdy!'
+ fprint(f, b'Howdy!')
def test_error_reading_blob(self):
fs = self.make_one()
@@ -253,7 +253,7 @@ def test_append(self):
path = os.path.join(self.tmp, 'foo')
with fs.open('foo', 'a') as f:
- print >> f, b'Daddy!'
+ fprint(f, b'Daddy!')
self.assertEqual(fs.open('foo', 'rb').read(), b'Hello!\n')
self.assertEqual(open(path).read(), b'Hello!\n')
self.assertEqual(fs.open('foo', 'rb').read(), b'Hello!\nDaddy!\n')
@@ -548,25 +548,25 @@ def test_merge_add_different_file_same_path(self):
def test_merge_file(self):
fs = self.make_one()
with fs.open('foo', 'w') as f:
- print >> f, b'One'
- print >> f, b'Two'
- print >> f, b'Three'
- print >> f, b'Four'
- print >> f, b'Five'
+ fprint(f, b'One')
+ fprint(f, b'Two')
+ fprint(f, b'Three')
+ fprint(f, b'Four')
+ fprint(f, b'Five')
transaction.commit()
base = fs.get_base()
with fs.open('foo', 'w') as f:
- print >> f, b'One'
- print >> f, b'Dos'
- print >> f, b'Three'
- print >> f, b'Four'
- print >> f, b'Five'
+ fprint(f, b'One')
+ fprint(f, b'Dos')
+ fprint(f, b'Three')
+ fprint(f, b'Four')
+ fprint(f, b'Five')
transaction.commit()
fs.set_base(base)
with fs.open('foo', 'a') as f:
- print >> f, b'Sei'
+ fprint(f, b'Sei')
transaction.commit()
self.assertEqual(list(fs.open('foo').readlines()), [
@@ -652,3 +652,8 @@ def test_called_process_error(self, Popen):
with self.assertRaises(subprocess.CalledProcessError):
with _popen(['what', 'ever']):
pass
+
+
+def fprint(f, s):
+ f.write(s)
+ f.write('\n')

0 comments on commit 533a336

Please sign in to comment.
Something went wrong with that request. Please try again.