Skip to content

Commit 71c28b4

Browse files
authored
Issue 96 (#97)
* 🐛 regression: unknown file type shall trigger NoSupportingPluginFound. fix #96 * This is an auto-commit, updating project meta data, such as changelog.rst, contributors.rst * 💚 update coding style. #96 * 🔬 more test coverage Co-authored-by: chfw <[email protected]>
1 parent b77fc81 commit 71c28b4

File tree

8 files changed

+46
-39
lines changed

8 files changed

+46
-39
lines changed

CHANGELOG.rst

+8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
Change log
22
================================================================================
33

4+
0.6.3 - tbd
5+
--------------------------------------------------------------------------------
6+
7+
**updated**
8+
9+
#. `#96 <https://github.com/pyexcel/pyexcel-io/issues/96>`_: regression: unknown
10+
file type shall trigger NoSupportingPluginFound
11+
412
0.6.2 - 7.10.2020
513
--------------------------------------------------------------------------------
614

changelog.yml

+6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
name: pyexcel-io
22
organisation: pyexcel
33
releases:
4+
- changes:
5+
- action: updated
6+
details:
7+
- "`#96`: regression: unknown file type shall trigger NoSupportingPluginFound"
8+
version: 0.6.3
9+
date: tbd
410
- changes:
511
- action: updated
612
details:

pyexcel_io/exceptions.py

-6
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,6 @@ class SupportingPluginAvailableButNotInstalled(Exception):
2121
pass
2222

2323

24-
class UpgradePlugin(Exception):
25-
"""raised when a known plugin is not compatible"""
26-
27-
pass
28-
29-
3024
class IntegerAccuracyLossError(Exception):
3125
"""
3226
When an interger is greater than 999999999999999, ods loses its accuracy.

pyexcel_io/reader.py

+7-18
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from pyexcel_io import exceptions
2-
from pyexcel_io.book import _convert_content_to_stream
31
from pyexcel_io.sheet import SheetReader
42
from pyexcel_io.plugins import NEW_READERS
53
from pyexcel_io._compact import OrderedDict
@@ -53,23 +51,14 @@ def open(self, file_name, **keywords):
5351

5452
def open_content(self, file_content, **keywords):
5553
self.keywords, native_sheet_keywords = clean_keywords(keywords)
56-
try:
57-
if self.reader_class is None:
58-
self.reader_class = NEW_READERS.get_a_plugin(
59-
self.file_type, location="content", library=self.library
60-
)
61-
self.reader = self.reader_class(
62-
file_content, self.file_type, **native_sheet_keywords
63-
)
64-
return self.reader
65-
except (
66-
exceptions.NoSupportingPluginFound,
67-
exceptions.SupportingPluginAvailableButNotInstalled,
68-
):
69-
file_stream = _convert_content_to_stream(
70-
file_content, self.file_type
54+
if self.reader_class is None:
55+
self.reader_class = NEW_READERS.get_a_plugin(
56+
self.file_type, location="content", library=self.library
7157
)
72-
return self.open_stream(file_stream, **native_sheet_keywords)
58+
self.reader = self.reader_class(
59+
file_content, self.file_type, **native_sheet_keywords
60+
)
61+
return self.reader
7362

7463
def open_stream(self, file_stream, **keywords):
7564
self.keywords, native_sheet_keywords = clean_keywords(keywords)

pyexcel_io/readers/__init__.py

+5
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,9 @@
2929
file_types=["csvz", "tsvz"],
3030
locations=["file", "memory"],
3131
stream_type="binary",
32+
).add_a_reader(
33+
relative_plugin_class_path="csvz.ContentReader",
34+
file_types=["csvz", "tsvz"],
35+
locations=["content"],
36+
stream_type="binary",
3237
)

pyexcel_io/readers/csvz.py

+7
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
:license: New BSD License, see LICENSE for more details
99
"""
1010
import zipfile
11+
from io import BytesIO
1112

1213
import chardet
1314
from pyexcel_io import constants
@@ -48,6 +49,12 @@ def read_sheet(self, index):
4849
return CSVinMemoryReader(NamedContent(name, sheet), **self.keywords)
4950

5051

52+
class ContentReader(FileReader):
53+
def __init__(self, file_content, file_type, **keywords):
54+
io = BytesIO(file_content)
55+
super().__init__(io, file_type, **keywords)
56+
57+
5158
def _get_sheet_name(filename):
5259
len_of_a_dot = 1
5360
len_of_csv_word = 3

tests/test_issues.py

+7-15
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
#!/usr/bin/env python
2-
# -*- coding: utf-8 -*-
3-
41
import os
52

63
import pyexcel as p
74
from pyexcel_io import get_data, save_data
5+
from pyexcel_io.exceptions import NoSupportingPluginFound
86

97
from nose import SkipTest
10-
from nose.tools import eq_
8+
from nose.tools import eq_, raises
119

1210
IN_TRAVIS = "TRAVIS" in os.environ
1311

@@ -41,17 +39,6 @@ def test_issue_23():
4139
eq_(data["issue23.csv"], expected)
4240

4341

44-
# def test_issue_28():
45-
# from pyexcel_io.plugins import readers
46-
# from pyexcel_io.exceptions import UpgradePlugin
47-
# expected = "Please upgrade the plugin '%s' according to "
48-
# expected += "plugin compactibility table."
49-
# try:
50-
# readers.load_me_later('pyexcel_test')
51-
# except UpgradePlugin as e:
52-
# eq_(str(e), expected % 'pyexcel_test')
53-
54-
5542
def test_issue_33_34():
5643
import mmap
5744

@@ -154,5 +141,10 @@ def test_pyexcel_issue_138():
154141
os.unlink("test.csv")
155142

156143

144+
@raises(NoSupportingPluginFound)
145+
def test_issue_96():
146+
get_data("foo-bar-data", file_type="Idonotexist")
147+
148+
157149
def get_fixture(file_name):
158150
return os.path.join("tests", "fixtures", file_name)

tests/test_service.py

+6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from pyexcel_io.service import (
44
date_value,
55
time_value,
6+
float_value,
67
boolean_value,
78
ods_bool_value,
89
ods_date_value,
@@ -162,3 +163,8 @@ def test_time_value():
162163
test_time_value = "PT23H00M01S"
163164
delta = time_value(test_time_value)
164165
eq_(delta, time(23, 0, 1))
166+
167+
168+
def test_float_value():
169+
a = float_value("1.2")
170+
eq_(a, 1.2)

0 commit comments

Comments
 (0)