def __getitem__(self, expression): if isinstance(expression, int): return self.getFeatureByIndex(expression) elif isinstance(parse_literal(expression), int): return self.getFeatureByIndex(parse_literal(expression)) else: try: field, value = expression.split('=') except AttributeError: raise KeyError('invalid expression') feat = self.getFeatureByAttribute(field, parse_literal(value)) return feature2vector(feat, ref=self)
def test_parse_literal(): assert anc.parse_literal(['1', '2.2', 'a']) == [1, 2.2, 'a'] with pytest.raises(IOError): anc.parse_literal(1)
def test_parse_literal_error(self): with self.assertRaises(IOError): anc.parse_literal(1)
def test_parse_literal(self): self.assertEqual(anc.parse_literal(['1', '2.2', 'a']), [1, 2.2, 'a'])