Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_stream_ods_sheet_by_index_not_existent_2():
with pytest.raises(exceptions.SourceError) as excinfo:
Stream('data/table.ods', sheet='not-existent').open()
assert 'sheet "not-existent"' in str(excinfo.value)
def test_ndjson_scalar():
stream = StringIO(
'1\n'
'2\n'
)
loader = Mock(load=Mock(return_value=stream))
parser = NDJSONParser(loader)
parser.open(None)
with pytest.raises(exceptions.SourceError):
list(parser.extended_rows)
def open(self, source, encoding=None):
self.close()
package = datapackage.DataPackage(source)
if isinstance(self.__resource_pointer, six.string_types):
self.__resource = package.get_resource(self.__resource_pointer)
else:
try:
self.__resource = package.resources[self.__resource_pointer]
except (TypeError, IndexError):
pass
if not self.__resource:
message = 'Data package "%s" doesn\'t have resource "%s"'
raise exceptions.SourceError(message % (source, self.__resource_pointer))
self.__resource.infer()
self.__encoding = self.__resource.descriptor.get('encoding')
self.__fragment = self.__resource.name
self.reset()
def __init__(self, loader, force_parse=False, table=None, order_by=None):
# Ensure table
if table is None:
raise exceptions.TabulatorException('Format `sql` requires `table` option.')
# Set attributes
self.__loader = loader
self.__table = table
self.__order_by = order_by
self.__force_parse = force_parse
self.__engine = None
self.__extended_rows = None
self.__encoding = None