Skip to content

Commit

Permalink
Test coverage.
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Rossi committed Mar 17, 2011
1 parent 8abbd6c commit 9364fd2
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 5 deletions.
7 changes: 3 additions & 4 deletions repoze/catalog/query.py
Expand Up @@ -603,6 +603,8 @@ def __init__(self, name):
def __repr__(self):
return '%s(%r)' % (self.__class__.__name__, self.name)

__str__ = __repr__

def __eq__(self, right):
if isinstance(right, Name):
return right.name == self.name
Expand Down Expand Up @@ -867,10 +869,7 @@ def _index_name(self, node):

def _value(self, node):
if isinstance(node, ast.Name):
try:
return Name(node.id)
except:
raise NameError(node.id)
return Name(node.id)
return node


Expand Down
39 changes: 38 additions & 1 deletion repoze/catalog/tests/test_query.py
Expand Up @@ -382,7 +382,7 @@ def test_apply_w_names(self):
from repoze.catalog.query import Name
catalog = DummyCatalog()
inst = self._makeOne('index', Name('foo'), Name('bar'))
result = inst._apply(catalog, {'foo': 'begin', 'foo': 'bar'})
result = inst._apply(catalog, {'foo': 'begin', 'bar': 'end'})
self.assertEqual(result, ('begin', 'end', False, False))
self.assertEqual(
catalog.index.range, ('begin', 'end', False, False))
Expand All @@ -392,6 +392,7 @@ def test_apply_w_names_missing(self):
catalog = DummyCatalog()
inst = self._makeOne('index', Name('foo'), Name('bar'))
self.assertRaises(NameError, inst._apply, catalog, {})
self.assertRaises(NameError, inst._apply, catalog, {'foo': 'begin'})

def test_apply_exclusive(self):
catalog = DummyCatalog()
Expand Down Expand Up @@ -627,6 +628,24 @@ def test_iter_children(self):
self.assertEqual(list(o.iter_children()), [query])


class TestName(unittest.TestCase):

def _makeOne(self):
from repoze.catalog.query import Name as cls
return cls('foo')

def test_to_str(self):
o = self._makeOne()
self.assertEqual(str(o), "Name('foo')")

def test_eq(self):
o1 = self._makeOne()
o2 = self._makeOne()
self.failIf(o1 is o2)
self.failUnless(o1 == o2)
self.failIf(o1 == 'foo')


class Test_parse_query(unittest.TestCase):
def tearDown(self):
from repoze.catalog import query
Expand Down Expand Up @@ -938,6 +957,15 @@ def test_convert_gtlt_to_range(self):
self.assertEqual(op.start_exclusive, True)
self.assertEqual(op.end_exclusive, True)

def test_convert_ltgt_to_range(self):
from repoze.catalog.query import InRange
op = self._call_fut("a > 0 and a < 1")
self.failUnless(isinstance(op, InRange))
self.assertEqual(op._start, 0)
self.assertEqual(op._end, 1)
self.assertEqual(op.start_exclusive, True)
self.assertEqual(op.end_exclusive, True)

def test_convert_gtlt_to_not_in_range(self):
from repoze.catalog.query import NotInRange
op = self._call_fut("a < 0 or a > 1")
Expand All @@ -947,6 +975,15 @@ def test_convert_gtlt_to_not_in_range(self):
self.assertEqual(op.start_exclusive, False)
self.assertEqual(op.end_exclusive, False)

def test_convert_ltgt_to_not_in_range(self):
from repoze.catalog.query import NotInRange
op = self._call_fut("a > 1 or a < 0")
self.failUnless(isinstance(op, NotInRange))
self.assertEqual(op._start, 0)
self.assertEqual(op._end, 1)
self.assertEqual(op.start_exclusive, False)
self.assertEqual(op.end_exclusive, False)

def test_convert_gtlt_child_left_nephew_left(self):
from repoze.catalog.query import Eq
from repoze.catalog.query import And
Expand Down

0 comments on commit 9364fd2

Please sign in to comment.