from pytest import raises
from perspective import PerspectiveError
import perspective as psp
client = psp.Server().new_local_client()
Table = client.table
class TestException(object):
def test_instantiation_exception_table(self):
from perspective import Table
with raises(TypeError) as ex:
Table()
assert "Do not call Table's constructor directly" in str(ex.value)
def test_instantiation_exception_view(self):
from perspective import View
with raises(TypeError) as ex:
View()
assert "Do not call View's constructor directly" in str(ex.value)
def test_exception_from_core(self):
tbl = Table({"a": [1, 2, 3]})
with raises(PerspectiveError) as ex:
tbl.view(group_by=["b"])
assert str(ex.value) == "Abort(): Invalid column 'b' found in View group_by.\n"
def test_exception_from_core_catch_generic(self):
tbl = Table({"a": [1, 2, 3]})
with raises(Exception) as ex:
tbl.view(group_by=["b"])
assert str(ex.value) == "Abort(): Invalid column 'b' found in View group_by.\n"
def test_exception_from_core_correct_types(self):
tbl = Table({"a": [1, 2, 3]})
with raises(PerspectiveError) as ex:
tbl.view()
tbl.delete()
assert str(ex.value) == "Abort(): Cannot delete table with views"
with raises(PerspectiveError) as ex:
tbl.view(group_by=["b"])
assert str(ex.value) == "Abort(): Invalid column 'b' found in View group_by.\n"