Strengthen check for invalid columns.
Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
This commit is contained in:
parent
7fdde37c27
commit
16c9da38e0
2 changed files with 20 additions and 1 deletions
|
|
@ -371,8 +371,10 @@ class Schema:
|
|||
elif rectype in ['col', 'column']:
|
||||
try:
|
||||
self._columns = int(i.fields[1])
|
||||
if self._columns <= 0:
|
||||
raise ValueError
|
||||
except ValueError:
|
||||
raise newfol.exception.SchemaError("has non-integral " +
|
||||
raise newfol.exception.SchemaError("has invalid " +
|
||||
"number of columns")
|
||||
elif rectype in ['txn', 'transaction']:
|
||||
self._txntype = i.fields[1:]
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
from newfol.exception import SchemaError
|
||||
from newfol.database import DatabaseVersion, Database, Schema, Singleton
|
||||
from newfol.filemanip import Record
|
||||
import tempfile
|
||||
|
|
@ -169,6 +170,22 @@ class TestExtraSchemaConfig(unittest.TestCase):
|
|||
# Ensure no exception is raised.
|
||||
|
||||
|
||||
class TestSchemaColumns(unittest.TestCase):
|
||||
def check_invalid(self, value):
|
||||
with self.assertRaises(SchemaError):
|
||||
tdb = TemporaryDatabase("col:%s\n" % value)
|
||||
tdb.db
|
||||
|
||||
def test_non_integral(self):
|
||||
self.check_invalid(3.5)
|
||||
|
||||
def test_negative(self):
|
||||
self.check_invalid(-1)
|
||||
|
||||
def test_zero(self):
|
||||
self.check_invalid(0)
|
||||
|
||||
|
||||
class TestExecutionAllowed(unittest.TestCase):
|
||||
def do_test(self, expected, schema, configv):
|
||||
tdb = TemporaryDatabase(schema)
|
||||
|
|
|
|||
Loading…
Reference in a new issue