0bc8eed0c6d3 — Oben Sonne 9 years ago
use distinct exceptions for unknown relations
2 files changed, 10 insertions(+), 10 deletions(-)

M src/deeno/db.py
M src/tests/test_db.py
M src/deeno/db.py +8 -5
@@ 21,6 21,10 @@ class NoMatchingRecord(DeenoException):
     pass
 
 
+class RelationNotFound(DeenoException):
+    pass
+
+
 class Record(dict):
 
     def __init__(self, table, *args, **kwargs):

          
@@ 350,10 354,8 @@ class SQLiteDatabase(Database):
         q = 'SELECT type FROM sqlite_master WHERE name = ?'
         p = [name]
         r = self.fetchone(q, p)
-        if r is None:
-            raise ValueError('no such relation: %r' % name)
-        if r.type not in ('table', 'view'):
-            raise ValueError('unknown relation type: %r (%r)' % (r.type, name))
+        if r is None or r.type not in ('table', 'view'):
+            raise RelationNotFound('view or table %r not found' % name)
 
         pk = None
         if r.type == 'table':

          
@@ 436,7 438,8 @@ class PostgresDatabase(Database):
                 break
 
         if rtype is None:
-            raise ValueError('no view/table %r in current search path' % name)
+            raise RelationNotFound('no view/table %r in current search path' %
+                name)
 
         if rtype == 'table':
             q = """

          
M src/tests/test_db.py +2 -5
@@ 12,7 12,7 @@ from nose.tools import eq_, ok_, raises
 import mock
 
 from deeno.db import (Record, Relation, Relatiomat, NoMatchingRecord,
-    SQLiteDatabase, PostgresDatabase)
+    SQLiteDatabase, PostgresDatabase, RelationNotFound)
 
 from tests import MockedDatabase
 

          
@@ 421,11 421,8 @@ class AbstractDatabaseTest(object):
         eq_(rt, 'table')
         eq_(pk, ('c1', 'c2'))
 
-        try:
+        with self.assertRaises(RelationNotFound):
             self.db.get_relation_info('xx')
-            ok_(False)
-        except ValueError:
-            pass
 
     def test_execute(self):