def test_invalid_selection(self): """Test invalid selections. In theory this should never happen, since ``ConstraintExpression`` object are constructly directly from existing children. """ with self.assertRaises(ConstraintExpressionError): self.data[ConstraintExpression("a.e<1")] with self.assertRaises(ConstraintExpressionError): self.data[ConstraintExpression("a.d<foo")]
def test_regexp(self): sequence = SequenceType("sequence") sequence["name"] = BaseType("name") sequence.data = IterData([ ("John", "Paul", "George", "Ringo"), ], sequence) filtered = sequence[ConstraintExpression('sequence.name=~"J.*"')] self.assertEqual(list(filtered.iterdata()), [("John", )])
def test_or(self): """Expressions cannot be ORed.""" ce1 = ConstraintExpression("a>1") ce2 = ConstraintExpression("b>0") with self.assertRaises(ConstraintExpressionError): ce1 | ce2
def test_and(self): """Test CE addition.""" ce1 = ConstraintExpression("a>1") ce2 = ConstraintExpression("b>0") ce3 = ce1 & ce2 self.assertEqual(str(ce3), "a>1&b>0")
def test_unicode(self): """Test unicode representation.""" ce = ConstraintExpression("a>1") self.assertEqual(text_type(ce), "a>1")
def test_str(self): """Test string representation.""" ce = ConstraintExpression("a>1") self.assertEqual(str(ce), "a>1")
def __lt__(self, other): return ConstraintExpression('%s<%s' % (self.id, encode(other)))