From 1c6f4c19289732bd13507eba9e54c9d692957137 Mon Sep 17 00:00:00 2001 From: Kevin Brown Date: Sun, 13 Jul 2014 15:35:24 -0400 Subject: Automated PEP 8 fixes --- gitdb/test/test_example.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'gitdb/test/test_example.py') diff --git a/gitdb/test/test_example.py b/gitdb/test/test_example.py index 611ae42..f45063b 100644 --- a/gitdb/test/test_example.py +++ b/gitdb/test/test_example.py @@ -11,17 +11,17 @@ from gitdb.util import pool from cStringIO import StringIO from async import IteratorReader - + class TestExamples(TestBase): - + def test_base(self): ldb = LooseObjectDB(fixture_path("../../../.git/objects")) - + for sha1 in ldb.sha_iter(): oinfo = ldb.info(sha1) ostream = ldb.stream(sha1) assert oinfo[:3] == ostream[:3] - + assert len(ostream.read()) == ostream.size assert ldb.has_object(oinfo.binsha) # END for each sha in database @@ -32,33 +32,33 @@ class TestExamples(TestBase): except UnboundLocalError: pass # END ignore exception if there are no loose objects - + data = "my data" istream = IStream("blob", len(data), StringIO(data)) - + # the object does not yet have a sha assert istream.binsha is None ldb.store(istream) # now the sha is set assert len(istream.binsha) == 20 assert ldb.has_object(istream.binsha) - - + + # async operation # Create a reader from an iterator reader = IteratorReader(ldb.sha_iter()) - + # get reader for object streams info_reader = ldb.stream_async(reader) - + # read one info = info_reader.read(1)[0] - + # read all the rest until depletion ostreams = info_reader.read() - + # set the pool to use two threads pool.set_size(2) - + # synchronize the mode of operation pool.set_size(0) -- cgit v1.2.1 From b6c493deb2341fb843d71b66b2aa23078638755c Mon Sep 17 00:00:00 2001 From: Kevin Brown Date: Sun, 13 Jul 2014 15:41:15 -0400 Subject: Pick off the low hanging fruit This fixes most of the import errors that came from using the implicit relative imports that Python 2 supports. This also fixes the use of `xrange`, which has replaced `range` in Python 3. The same has happened for `izip`, which is also being aliased. The octal number syntax changed in Python 3, so we are now converting from strings using the `int` built-in function, which will produce the same output across both versions of Python. --- gitdb/test/test_example.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'gitdb/test/test_example.py') diff --git a/gitdb/test/test_example.py b/gitdb/test/test_example.py index f45063b..f57cc50 100644 --- a/gitdb/test/test_example.py +++ b/gitdb/test/test_example.py @@ -3,12 +3,18 @@ # This module is part of GitDB and is released under # the New BSD License: http://www.opensource.org/licenses/bsd-license.php """Module with examples from the tutorial section of the docs""" -from lib import * +from gitdb.test.lib import * from gitdb import IStream from gitdb.db import LooseObjectDB from gitdb.util import pool - -from cStringIO import StringIO + +try: + from cStringIO import StringIO +except ImportError: + try: + from StringIO import StringIO + except ImportError: + from io import StringIO from async import IteratorReader -- cgit v1.2.1 From 087803ee30456c4942d9c18d82c1d686eb081a27 Mon Sep 17 00:00:00 2001 From: Kevin Brown Date: Sun, 13 Jul 2014 21:49:51 -0400 Subject: Making a bit of progress... This changes the internals to use BytesIO over StringIO, which fixed a few of the failing tests in Python 3. We are only importing from `io` now, instead of the entire chain, as this is available in Python 2.6+. --- gitdb/test/test_example.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'gitdb/test/test_example.py') diff --git a/gitdb/test/test_example.py b/gitdb/test/test_example.py index f57cc50..c714f10 100644 --- a/gitdb/test/test_example.py +++ b/gitdb/test/test_example.py @@ -8,13 +8,7 @@ from gitdb import IStream from gitdb.db import LooseObjectDB from gitdb.util import pool -try: - from cStringIO import StringIO -except ImportError: - try: - from StringIO import StringIO - except ImportError: - from io import StringIO +from io import StringIO from async import IteratorReader -- cgit v1.2.1 From 0cf09d3310cba7f33b9ebc9badf61ab721d12857 Mon Sep 17 00:00:00 2001 From: Kevin Brown Date: Sun, 13 Jul 2014 22:15:09 -0400 Subject: Fix Python 2 failures --- gitdb/test/test_example.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'gitdb/test/test_example.py') diff --git a/gitdb/test/test_example.py b/gitdb/test/test_example.py index c714f10..c644b88 100644 --- a/gitdb/test/test_example.py +++ b/gitdb/test/test_example.py @@ -8,7 +8,7 @@ from gitdb import IStream from gitdb.db import LooseObjectDB from gitdb.util import pool -from io import StringIO +from io import BytesIO from async import IteratorReader @@ -33,8 +33,8 @@ class TestExamples(TestBase): pass # END ignore exception if there are no loose objects - data = "my data" - istream = IStream("blob", len(data), StringIO(data)) + data = "my data".encode("ascii") + istream = IStream("blob", len(data), BytesIO(data)) # the object does not yet have a sha assert istream.binsha is None -- cgit v1.2.1 From b64c771bcb2ec336dd549cfe9d072340c886f3c9 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Thu, 13 Nov 2014 12:17:01 +0100 Subject: Fixed all applicable lint issues --- gitdb/test/test_example.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'gitdb/test/test_example.py') diff --git a/gitdb/test/test_example.py b/gitdb/test/test_example.py index c644b88..433518c 100644 --- a/gitdb/test/test_example.py +++ b/gitdb/test/test_example.py @@ -3,7 +3,10 @@ # This module is part of GitDB and is released under # the New BSD License: http://www.opensource.org/licenses/bsd-license.php """Module with examples from the tutorial section of the docs""" -from gitdb.test.lib import * +from gitdb.test.lib import ( + TestBase, + fixture_path +) from gitdb import IStream from gitdb.db import LooseObjectDB from gitdb.util import pool -- cgit v1.2.1 From bf942a913d69eb2079f9e82888aaccf2f6222643 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Thu, 13 Nov 2014 13:31:32 +0100 Subject: Fully removed all async dependencies --- gitdb/test/test_example.py | 23 ----------------------- 1 file changed, 23 deletions(-) (limited to 'gitdb/test/test_example.py') diff --git a/gitdb/test/test_example.py b/gitdb/test/test_example.py index 433518c..aa43a09 100644 --- a/gitdb/test/test_example.py +++ b/gitdb/test/test_example.py @@ -9,12 +9,9 @@ from gitdb.test.lib import ( ) from gitdb import IStream from gitdb.db import LooseObjectDB -from gitdb.util import pool from io import BytesIO -from async import IteratorReader - class TestExamples(TestBase): def test_base(self): @@ -45,23 +42,3 @@ class TestExamples(TestBase): # now the sha is set assert len(istream.binsha) == 20 assert ldb.has_object(istream.binsha) - - - # async operation - # Create a reader from an iterator - reader = IteratorReader(ldb.sha_iter()) - - # get reader for object streams - info_reader = ldb.stream_async(reader) - - # read one - info = info_reader.read(1)[0] - - # read all the rest until depletion - ostreams = info_reader.read() - - # set the pool to use two threads - pool.set_size(2) - - # synchronize the mode of operation - pool.set_size(0) -- cgit v1.2.1