Skip to content

Commit

Permalink
bug fixes on py3
Browse files Browse the repository at this point in the history
  • Loading branch information
chfw committed May 15, 2015
1 parent 9970184 commit e0ca79e
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 9 deletions.
9 changes: 5 additions & 4 deletions doc/source/django.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ Suppose you have these data::
... [4, 5, 6]
... ]
>>> save_data(DB_DJANGO, data[1:], models={DEFAULT_SHEET_NAME: [model, data[0], None, None]})
>>> model.objects.objs
[{'Y': 2, 'X': 1, 'Z': 3}, {'Y': 5, 'X': 4, 'Z': 6}]
>>> import pprint
>>> pprint.pprint(model.objects.objs)
[{'X': 1, 'Y': 2, 'Z': 3}, {'X': 4, 'Y': 5, 'Z': 6}]

Read data from a django model
--------------------------------------------------------------------------------
Expand Down Expand Up @@ -107,8 +108,8 @@ In order to store a dictionary data structure, you need to do some transformatio
... "Sheet2": [model2, data['Sheet2'][0], None, None]
... }
>>> save_data(DB_DJANGO, to_store, models=models)
>>> model1.objects.objs
[{'Y': 4, 'X': 1, 'Z': 7}, {'Y': 5, 'X': 2, 'Z': 8}, {'Y': 6, 'X': 3, 'Z': 9}]
>>> pprint.pprint(model1.objects.objs)
[{'X': 1, 'Y': 4, 'Z': 7}, {'X': 2, 'Y': 5, 'Z': 8}, {'X': 3, 'Y': 6, 'Z': 9}]
>>> model2.objects.objs
[{'A': 1, 'C': 7, 'B': 4}, {'A': 2, 'C': 8, 'B': 5}, {'A': 3, 'C': 9, 'B': 6}]

Expand Down
4 changes: 2 additions & 2 deletions doc/source/extendedcsv.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Saving multiple sheets as CSV format
>>> if sys.version_info[0] < 3:
... from StringIO import StringIO
... else:
... from io import BytesIO as StringIO
... from io import StringIO
>>> from pyexcel_io import OrderedDict


Expand Down Expand Up @@ -56,7 +56,7 @@ into memory::
>>> data.update({"Sheet 1": [[1, 2, 3], [4, 5, 6]]})
>>> data.update({"Sheet 2": [[7, 8, 9], [10, 11, 12]]})
>>> io = StringIO()
>>> save_data(io, data, 'csv')
>>> save_data(io, data)
>>> # do something with the io
>>> # In reality, you might give it to your http response
>>> # object for downloading
Expand Down
2 changes: 1 addition & 1 deletion doc/source/plaincsv.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Write to a csv file
>>> if sys.version_info[0] < 3:
... from StringIO import StringIO
... else:
... from io import BytesIO as StringIO
... from io import StringIO
>>> from pyexcel_io import OrderedDict


Expand Down
2 changes: 0 additions & 2 deletions tests/test_csv_book.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,6 @@ def test_book_writer(self):
b.close()
with open(self.test_file, 'r') as f:
content = f.read().replace('\r', '')
print content.strip('\n').split('\n')
print self.result.split('\n')
assert content.strip('\n') == self.result

def tearDown(self):
Expand Down
5 changes: 5 additions & 0 deletions tests/test_csvz_book.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import os
from pyexcel_io import CSVZipBook, CSVZipWriter
import zipfile
import sys
PY2 = sys.version_info[0] == 2


class TestCSVZ:
def setUp(self):
Expand All @@ -17,6 +20,8 @@ def test_writing(self):
zip = zipfile.ZipFile(self.file, 'r')
assert zip.namelist() == [file_name]
content = zip.read(file_name)
if not PY2:
content = content.decode('utf-8')
assert content.replace('\r','').strip('\n') == "1,2,3"

def test_reading(self):
Expand Down

0 comments on commit e0ca79e

Please sign in to comment.