diff --git a/lib/newfol/database.py b/lib/newfol/database.py index 649f2b9..c14d1e8 100644 --- a/lib/newfol/database.py +++ b/lib/newfol/database.py @@ -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:] diff --git a/test/testdatabase.py b/test/testdatabase.py index 1361a69..b5de4d4 100755 --- a/test/testdatabase.py +++ b/test/testdatabase.py @@ -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)