def test_complex(self): parsed = mask.parse('field1, nested{field, sub{subfield}}, field2') expected = [ 'field1', mask.Nested('nested', ['field', mask.Nested('sub', ['subfield'])]), 'field2' ] self.assertEqual(parsed, expected)
def test_complex(self): parsed = mask.parse('field1, nested{field, sub{subfield}}, field2') expected = [ 'field1', mask.Nested('nested', [ 'field', mask.Nested('sub', ['subfield']) ]), 'field2' ] self.assertEqual(parsed, expected)
def test_one_field(self): self.assertEqual(mask.parse('field_name'), ['field_name'])
def test_empty_mask(self): self.assertEqual(mask.parse(''), [])
def parse(self, value): return mask.parse(value)
def test_coma_after_bracket(self): with self.assertRaises(mask.ParseError): mask.parse('nested{,}')
def test_consecutive_coma(self): with self.assertRaises(mask.ParseError): mask.parse('field,,')
def test_missing_closing_bracket(self): with self.assertRaises(mask.ParseError): mask.parse('nested{')
def test_star(self): parsed = mask.parse('nested{field1,field2},*') expected = [mask.Nested('nested', ['field1', 'field2']), '*'] self.assertEqual(parsed, expected)
def test_nested_fields(self): parsed = mask.parse('nested{field1,field2}') expected = [mask.Nested('nested', ['field1', 'field2'])] self.assertEqual(parsed, expected)
def test_multiple_field(self): parsed = mask.parse('field1, field2,field3') self.assertEqual(parsed, ['field1', 'field2', 'field3'])
def test_coma_before_bracket(self): with self.assertRaises(mask.ParseError): mask.parse('field,{}')
def test_unexpected_closing_bracket(self): with self.assertRaises(mask.ParseError): mask.parse('{field}}')
def parse(self, value): return mask.parse('{' + value + '}')