Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Make sure all existing tests are explicitly using binary i/o.

  • Loading branch information...
commit 7d4a49f6eebfc0be0fe82518dd43e087bbaefe36 1 parent 923aef7
@chrisrossi chrisrossi authored
Showing with 94 additions and 91 deletions.
  1. +2 −1  acidfs/__init__.py
  2. +92 −90 acidfs/tests.py
View
3  acidfs/__init__.py
@@ -1054,7 +1054,8 @@ def _check_output(*popenargs, **kwargs):
Stolen straight from Python 2.7.
"""
if 'stdout' in kwargs:
- raise ValueError('stdout argument not allowed, it will be overridden.')
+ raise ValueError(
+ 'stdout argument not allowed, it will be overridden.')
process = subprocess.Popen(stdout=subprocess.PIPE, *popenargs, **kwargs)
output, unused_err = process.communicate()
retcode = process.poll()
View
182 acidfs/tests.py
@@ -89,20 +89,20 @@ def assertDirectoryNotEmpty(self, path):
def test_read_write_file(self):
fs = self.make_one()
- with fs.open('foo', 'w') as f:
+ with fs.open('foo', 'wb') as f:
self.assertTrue(f.writable())
fprint(f, b'Hello')
with self.assertNoSuchFileOrDirectory('foo'):
- fs.open('foo')
- self.assertEqual(fs.open('foo').read(), b'Hello\n')
+ fs.open('foo', 'rb')
+ self.assertEqual(fs.open('foo', 'rb').read(), b'Hello\n')
actual_file = os.path.join(self.tmp, 'foo')
self.assertFalse(os.path.exists(actual_file))
transaction.commit()
- with fs.open('foo') as f:
+ with fs.open('foo', 'rb') as f:
self.assertTrue(f.readable())
self.assertEqual(f.read(), b'Hello\n')
- with open(actual_file) as f:
- self.assertEqual(f.read(), 'Hello\n')
+ with open(actual_file, 'rb') as f:
+ self.assertEqual(f.read(), b'Hello\n')
transaction.commit() # Nothing to commit
def test_read_write_file_in_subfolder(self):
@@ -110,64 +110,64 @@ def test_read_write_file_in_subfolder(self):
self.assertFalse(fs.isdir('foo'))
fs.mkdir('foo')
self.assertTrue(fs.isdir('foo'))
- with fs.open('foo/bar', 'w') as f:
+ with fs.open('foo/bar', 'wb') as f:
fprint(f, b'Hello')
- with fs.open('foo/bar') as f:
+ with fs.open('foo/bar', 'rb') as f:
self.assertEqual(f.read(), b'Hello\n')
actual_file = os.path.join(self.tmp, 'foo', 'bar')
self.assertFalse(os.path.exists(actual_file))
transaction.commit()
self.assertTrue(fs.isdir('foo'))
self.assertFalse(fs.isdir('foo/bar'))
- with fs.open('foo/bar') as f:
+ with fs.open('foo/bar', 'rb') as f:
+ self.assertEqual(f.read(), b'Hello\n')
+ with open(actual_file, 'rb') as f:
self.assertEqual(f.read(), b'Hello\n')
- with open(actual_file) as f:
- self.assertEqual(f.read(), 'Hello\n')
def test_read_write_file_in_subfolder_bare_repo(self):
fs = self.make_one(bare=True)
self.assertFalse(fs.isdir('foo'))
fs.mkdir('foo')
self.assertTrue(fs.isdir('foo'))
- with fs.open('foo/bar', 'w') as f:
+ with fs.open('foo/bar', 'wb') as f:
fprint(f, b'Hello')
- with fs.open('foo/bar') as f:
+ with fs.open('foo/bar', 'rb') as f:
self.assertEqual(f.read(), b'Hello\n')
transaction.commit()
self.assertTrue(fs.isdir('foo'))
self.assertFalse(fs.isdir('foo/bar'))
- with fs.open('foo/bar') as f:
+ with fs.open('foo/bar', 'rb') as f:
self.assertEqual(f.read(), b'Hello\n')
def test_open_edge_cases(self):
fs = self.make_one()
with self.assertNoSuchFileOrDirectory('foo'):
- fs.open('foo')
+ fs.open('foo', 'rb')
with self.assertNoSuchFileOrDirectory('foo/bar'):
- fs.open('foo/bar', 'w')
+ fs.open('foo/bar', 'wb')
with self.assertIsADirectory('.'):
- fs.open('.')
+ fs.open('.', 'rb')
with self.assertIsADirectory('.'):
- fs.open('.', 'w')
+ fs.open('.', 'wb')
fs.mkdir('foo')
with self.assertIsADirectory('foo'):
- fs.open('foo', 'w')
+ fs.open('foo', 'wb')
- fs.open('bar', 'w').write(b'Howdy')
+ fs.open('bar', 'wb').write(b'Howdy')
with self.assertNotADirectory('bar/foo'):
- fs.open('bar/foo', 'w')
+ fs.open('bar/foo', 'wb')
with self.assertRaises(ValueError):
fs.open('foo', 'wtf')
- with fs.open('bar', 'w') as f:
+ with fs.open('bar', 'wb') as f:
fprint(f, b'Howdy!')
with self.assertRaises(ValueError) as cm:
transaction.commit()
@@ -180,7 +180,7 @@ def test_mkdir_edge_cases(self):
with self.assertNoSuchFileOrDirectory('foo/bar'):
fs.mkdir('foo/bar')
- fs.open('foo', 'w').write(b'Howdy!')
+ fs.open('foo', 'wb').write(b'Howdy!')
with self.assertNotADirectory('foo/bar'):
fs.mkdir('foo/bar')
@@ -195,7 +195,7 @@ def test_commit_metadata(self):
tx.note("A test commit.")
tx.setUser('Fred Flintstone')
tx.setExtendedInfo('email', 'fred@bed.rock')
- fs.open('foo', 'w').write(b'Howdy!')
+ fs.open('foo', 'wb').write(b'Howdy!')
transaction.commit()
output = _check_output(['git', 'log'], cwd=self.tmp)
@@ -208,7 +208,7 @@ def test_commit_metadata_extended_info_for_user(self):
tx.note("A test commit.")
tx.setExtendedInfo('user', 'Fred Flintstone')
tx.setExtendedInfo('email', 'fred@bed.rock')
- fs.open('foo', 'w').write(b'Howdy!')
+ fs.open('foo', 'wb').write(b'Howdy!')
transaction.commit()
output = _check_output(['git', 'log'], cwd=self.tmp)
@@ -217,55 +217,55 @@ 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:
+ with fs.open('foo', 'wb') as f:
fprint(f, b"Howdy!")
transaction.commit()
path = os.path.join(self.tmp, 'foo')
- with fs.open('foo', 'w') as f:
+ with fs.open('foo', 'wb') as f:
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(), 'Howdy!\n')
+ self.assertEqual(fs.open('foo', 'rb').read(), b'Howdy!\n')
+ self.assertEqual(fs.open('foo', 'rb').read(), b'Hello!\n')
+ self.assertEqual(open(path, 'rb').read(), b'Howdy!\n')
transaction.commit()
- self.assertEqual(open(path).read(), 'Hello!\n')
+ self.assertEqual(open(path, 'rb').read(), b'Hello!\n')
def test_error_writing_blob(self):
fs = self.make_one()
with self.assertRaises((IOError, subprocess.CalledProcessError)):
- with fs.open('foo', 'w') as f:
+ with fs.open('foo', 'wb') as f:
shutil.rmtree(os.path.join(self.tmp, '.git'))
fprint(f, b'Howdy!')
def test_error_reading_blob(self):
fs = self.make_one()
- fs.open('foo', 'w').write(b'a' * 10000)
+ fs.open('foo', 'wb').write(b'a' * 10000)
with self.assertRaises(subprocess.CalledProcessError):
- with fs.open('foo', 'r') as f:
+ with fs.open('foo', 'rb') as f:
shutil.rmtree(os.path.join(self.tmp, '.git'))
f.read()
def test_append(self):
fs = self.make_one()
- fs.open('foo', 'w').write(b'Hello!\n')
+ fs.open('foo', 'wb').write(b'Hello!\n')
transaction.commit()
path = os.path.join(self.tmp, 'foo')
- with fs.open('foo', 'a') as f:
+ with fs.open('foo', 'ab') as f:
fprint(f, b'Daddy!')
self.assertEqual(fs.open('foo', 'rb').read(), b'Hello!\n')
- self.assertEqual(open(path).read(), 'Hello!\n')
+ self.assertEqual(open(path, 'rb').read(), b'Hello!\n')
self.assertEqual(fs.open('foo', 'rb').read(), b'Hello!\nDaddy!\n')
- self.assertEqual(open(path).read(), 'Hello!\n')
+ self.assertEqual(open(path, 'rb').read(), b'Hello!\n')
transaction.commit()
self.assertEqual(fs.open('foo', 'rb').read(), b'Hello!\nDaddy!\n')
- self.assertEqual(open(path).read(), 'Hello!\nDaddy!\n')
+ self.assertEqual(open(path, 'rb').read(), b'Hello!\nDaddy!\n')
def test_rm(self):
fs = self.make_one()
- fs.open('foo', 'w').write(b'Hello\n')
+ fs.open('foo', 'wb').write(b'Hello\n')
transaction.commit()
path = os.path.join(self.tmp, 'foo')
@@ -286,7 +286,7 @@ def test_rm(self):
def test_rmdir(self):
fs = self.make_one()
fs.mkdir('foo')
- fs.open('foo/bar', 'w').write(b'Hello\n')
+ fs.open('foo/bar', 'wb').write(b'Hello\n')
transaction.commit()
path = os.path.join(self.tmp, 'foo')
@@ -308,7 +308,7 @@ def test_rmdir(self):
def test_rmtree(self):
fs = self.make_one()
fs.mkdirs('foo/bar')
- fs.open('foo/bar/baz', 'w').write(b'Hello\n')
+ fs.open('foo/bar/baz', 'wb').write(b'Hello\n')
with self.assertNotADirectory('foo/bar/baz/boz'):
fs.mkdirs('foo/bar/baz/boz')
transaction.commit()
@@ -333,7 +333,7 @@ def test_rmtree(self):
def test_empty(self):
fs = self.make_one()
self.assertTrue(fs.empty('/'))
- fs.open('foo', 'w').write(b'Hello!')
+ fs.open('foo', 'wb').write(b'Hello!')
self.assertFalse(fs.empty('/'))
with self.assertNotADirectory('foo'):
fs.empty('foo')
@@ -344,8 +344,8 @@ def test_mv(self):
fs = self.make_one()
fs.mkdirs('one/a')
fs.mkdirs('one/b')
- fs.open('one/a/foo', 'w').write(b'Hello!')
- fs.open('one/b/foo', 'w').write(b'Howdy!')
+ fs.open('one/a/foo', 'wb').write(b'Hello!')
+ fs.open('one/b/foo', 'wb').write(b'Howdy!')
transaction.commit()
with self.assertNoSuchFileOrDirectory('/'):
@@ -371,15 +371,17 @@ def test_mv(self):
fs.mv('one/b/foo', 'one/a/bar')
self.assertFalse(fs.exists('one/b/foo'))
- self.assertEqual(fs.open('one/a/bar').read(), b'Howdy!')
+ self.assertEqual(fs.open('one/a/bar', 'rb').read(), b'Howdy!')
self.assertTrue(pexists(j(self.tmp, 'one', 'b', 'foo')))
- self.assertEqual(open(j(self.tmp, 'one', 'a', 'bar')).read(), 'Hello!')
+ self.assertEqual(open(j(self.tmp, 'one', 'a', 'bar'), 'rb').read(),
+ b'Hello!')
transaction.commit()
self.assertFalse(fs.exists('one/b/foo'))
- self.assertEqual(fs.open('one/a/bar').read(), b'Howdy!')
+ self.assertEqual(fs.open('one/a/bar', 'rb').read(), b'Howdy!')
self.assertFalse(pexists(j(self.tmp, 'one', 'b', 'foo')))
- self.assertEqual(open(j(self.tmp, 'one', 'a', 'bar')).read(), 'Howdy!')
+ self.assertEqual(open(j(self.tmp, 'one', 'a', 'bar'), 'rb').read(),
+ b'Howdy!')
fs.mv('one/a', 'one/b')
self.assertFalse(fs.exists('one/a'))
@@ -397,7 +399,7 @@ def test_listdir(self):
fs = self.make_one()
fs.mkdirs('one/a')
fs.mkdir('two')
- fs.open('three', 'w').write(b'Hello!')
+ fs.open('three', 'wb').write(b'Hello!')
with self.assertNoSuchFileOrDirectory('bar'):
fs.listdir('bar')
@@ -415,8 +417,8 @@ def test_chdir(self):
fs.mkdirs('one/a')
fs.mkdir('two')
- fs.open('three', 'w').write(b'Hello!')
- fs.open('two/three', 'w').write(b'Haha!')
+ fs.open('three', 'wb').write(b'Hello!')
+ fs.open('two/three', 'wb').write(b'Haha!')
self.assertEqual(fs.cwd(), '/')
self.assertEqual(sorted(fs.listdir()), ['one', 'three', 'two'])
@@ -435,8 +437,8 @@ def test_chdir(self):
with fs.cd('/two'):
self.assertEqual(fs.cwd(), '/two')
self.assertEqual(fs.listdir(), ['three'])
- self.assertEqual(fs.open('three').read(), b'Haha!')
- self.assertEqual(fs.open('/three').read(), b'Hello!')
+ self.assertEqual(fs.open('three', 'rb').read(), b'Haha!')
+ self.assertEqual(fs.open('/three', 'rb').read(), b'Hello!')
self.assertEqual(fs.cwd(), '/one')
self.assertEqual(fs.listdir(), ['a'])
@@ -444,8 +446,8 @@ def test_chdir(self):
def test_conflict_error_on_first_commit(self):
from acidfs import ConflictError
fs = self.make_one()
- fs.open('foo', 'w').write(b'Hello!')
- open(os.path.join(self.tmp, 'foo'), 'w').write('Howdy!')
+ fs.open('foo', 'wb').write(b'Hello!')
+ open(os.path.join(self.tmp, 'foo'), 'wb').write(b'Howdy!')
_check_output(['git', 'add', '.'], cwd=self.tmp)
_check_output(['git', 'commit', '-m', 'Haha! First!'], cwd=self.tmp)
with self.assertRaises(ConflictError):
@@ -454,9 +456,9 @@ def test_conflict_error_on_first_commit(self):
def test_unable_to_merge_file(self):
from acidfs import ConflictError
fs = self.make_one()
- fs.open('foo', 'w').write(b'Hello!')
+ fs.open('foo', 'wb').write(b'Hello!')
transaction.commit()
- fs.open('foo', 'w').write(b'Party!')
+ fs.open('foo', 'wb').write(b'Party!')
open(os.path.join(self.tmp, 'foo'), 'wb').write(b'Howdy!')
_check_output(['git', 'add', '.'], cwd=self.tmp)
_check_output(['git', 'commit', '-m', 'Haha! First!'], cwd=self.tmp)
@@ -465,11 +467,11 @@ def test_unable_to_merge_file(self):
def test_merge_add_file(self):
fs = self.make_one()
- fs.open('foo', 'w').write(b'Hello!\n')
+ fs.open('foo', 'wb').write(b'Hello!\n')
transaction.commit()
- fs.open('bar', 'w').write(b'Howdy!\n')
- open(os.path.join(self.tmp, 'baz'), 'w').write('Ciao!\n')
+ fs.open('bar', 'wb').write(b'Howdy!\n')
+ open(os.path.join(self.tmp, 'baz'), 'wb').write(b'Ciao!\n')
_check_output(['git', 'add', 'baz'], cwd=self.tmp)
_check_output(['git', 'commit', '-m', 'haha'], cwd=self.tmp)
transaction.commit()
@@ -480,9 +482,9 @@ def test_merge_add_file(self):
def test_merge_rm_file(self):
fs = self.make_one(head='master')
- fs.open('foo', 'w').write(b'Hello\n')
- fs.open('bar', 'w').write(b'Grazie\n')
- fs.open('baz', 'w').write(b'Prego\n')
+ fs.open('foo', 'wb').write(b'Hello\n')
+ fs.open('bar', 'wb').write(b'Grazie\n')
+ fs.open('baz', 'wb').write(b'Prego\n')
transaction.commit()
fs.rm('foo')
@@ -496,8 +498,8 @@ def test_merge_rm_file(self):
def test_merge_rm_same_file(self):
fs = self.make_one(head='master')
- fs.open('foo', 'w').write(b'Hello\n')
- fs.open('bar', 'w').write(b'Grazie\n')
+ fs.open('foo', 'wb').write(b'Hello\n')
+ fs.open('bar', 'wb').write(b'Grazie\n')
transaction.commit()
base = fs.get_base()
@@ -507,7 +509,7 @@ def test_merge_rm_same_file(self):
fs.set_base(base)
fs.rm('foo')
# Do something else besides, so commit has different sha1
- fs.open('baz', 'w').write(b'Prego\n')
+ fs.open('baz', 'wb').write(b'Prego\n')
transaction.commit()
self.assertFalse(fs.exists('foo'))
@@ -515,39 +517,39 @@ def test_merge_rm_same_file(self):
def test_merge_add_same_file(self):
fs = self.make_one(head='master')
- fs.open('foo', 'w').write(b'Hello\n')
+ fs.open('foo', 'wb').write(b'Hello\n')
transaction.commit()
base = fs.get_base()
- fs.open('bar', 'w').write(b'Grazie\n')
+ fs.open('bar', 'wb').write(b'Grazie\n')
transaction.commit()
fs.set_base(base)
- fs.open('bar', 'w').write(b'Grazie\n')
+ fs.open('bar', 'wb').write(b'Grazie\n')
# Do something else besides, so commit has different sha1
- fs.open('baz', 'w').write(b'Prego\n')
+ fs.open('baz', 'wb').write(b'Prego\n')
transaction.commit()
- self.assertEqual(fs.open('bar').read(), b'Grazie\n')
+ self.assertEqual(fs.open('bar', 'rb').read(), b'Grazie\n')
def test_merge_add_different_file_same_path(self):
from acidfs import ConflictError
fs = self.make_one(head='master')
- fs.open('foo', 'w').write(b'Hello\n')
+ fs.open('foo', 'wb').write(b'Hello\n')
transaction.commit()
base = fs.get_base()
- fs.open('bar', 'w').write(b'Grazie\n')
+ fs.open('bar', 'wb').write(b'Grazie\n')
transaction.commit()
fs.set_base(base)
- fs.open('bar', 'w').write(b'Prego\n')
+ fs.open('bar', 'wb').write(b'Prego\n')
with self.assertRaises(ConflictError):
transaction.commit()
def test_merge_file(self):
fs = self.make_one()
- with fs.open('foo', 'w') as f:
+ with fs.open('foo', 'wb') as f:
fprint(f, b'One')
fprint(f, b'Two')
fprint(f, b'Three')
@@ -556,7 +558,7 @@ def test_merge_file(self):
transaction.commit()
base = fs.get_base()
- with fs.open('foo', 'w') as f:
+ with fs.open('foo', 'wb') as f:
fprint(f, b'One')
fprint(f, b'Dos')
fprint(f, b'Three')
@@ -565,11 +567,11 @@ def test_merge_file(self):
transaction.commit()
fs.set_base(base)
- with fs.open('foo', 'a') as f:
+ with fs.open('foo', 'ab') as f:
fprint(f, b'Sei')
transaction.commit()
- self.assertEqual(list(fs.open('foo').readlines()), [
+ self.assertEqual(list(fs.open('foo', 'rb').readlines()), [
b'One\n',
b'Dos\n',
b'Three\n',
@@ -580,11 +582,11 @@ def test_merge_file(self):
def test_set_base(self):
from acidfs import ConflictError
fs = self.make_one()
- fs.open('foo', 'w').write(b'Hello\n')
+ fs.open('foo', 'wb').write(b'Hello\n')
transaction.commit()
base = fs.get_base()
- fs.open('bar', 'w').write(b'Grazie\n')
+ fs.open('bar', 'wb').write(b'Grazie\n')
with self.assertRaises(ConflictError):
fs.set_base('whatever')
transaction.commit()
@@ -592,7 +594,7 @@ def test_set_base(self):
fs.set_base(base)
self.assertTrue(fs.exists('foo'))
self.assertFalse(fs.exists('bar'))
- fs.open('baz', 'w').write(b'Prego\n')
+ fs.open('baz', 'wb').write(b'Prego\n')
transaction.commit()
self.assertTrue(fs.exists('foo'))
@@ -601,29 +603,29 @@ def test_set_base(self):
def test_use_other_branch(self):
fs = self.make_one(head='foo')
- fs.open('foo', 'w').write(b'Hello\n')
+ fs.open('foo', 'wb').write(b'Hello\n')
transaction.commit()
fs2 = self.make_one()
- fs2.open('foo', 'w').write(b'Howdy!\n')
+ fs2.open('foo', 'wb').write(b'Howdy!\n')
transaction.commit()
- self.assertEqual(fs.open('foo').read(), b'Hello\n')
- self.assertEqual(fs2.open('foo').read(), b'Howdy!\n')
+ self.assertEqual(fs.open('foo', 'rb').read(), b'Hello\n')
+ self.assertEqual(fs2.open('foo', 'rb').read(), b'Howdy!\n')
def test_branch_and_then_merge(self):
fs = self.make_one()
- fs.open('foo', 'w').write(b'Hello')
+ fs.open('foo', 'wb').write(b'Hello')
transaction.commit()
fs2 = self.make_one(head='abranch')
fs2.set_base(fs.get_base())
- fs2.open('bar', 'w').write(b'Ciao')
- fs.open('baz', 'w').write(b'Hola')
+ fs2.open('bar', 'wb').write(b'Ciao')
+ fs.open('baz', 'wb').write(b'Hola')
transaction.commit()
fs.set_base('abranch')
- fs.open('beez', 'w').write(b'buzz')
+ fs.open('beez', 'wb').write(b'buzz')
transaction.commit()
self.assertTrue(fs.exists('foo'))
Please sign in to comment.
Something went wrong with that request. Please try again.