def test_raises_for_bad_feature(self): with self.assertRaises(ValueError): parser.Options('foobar') options = parser.Options() with self.assertRaises(ValueError): options.has_feature('foobar')
def test_has_feature(self): options = parser.Options() self.assertFalse(options.has_feature('dictionary-required')) self.assertFalse( options.has_feature(parser.Features.DICTIONARY_REQUIRED)) self.assertFalse( options.has_feature(parser.Features.DICTIONARY_DEFAULT)) options = parser.Options(parser.Features.DICTIONARY_REQUIRED) self.assertTrue(options.has_feature('dictionary-required')) self.assertTrue( options.has_feature(parser.Features.DICTIONARY_REQUIRED)) self.assertFalse( options.has_feature(parser.Features.DICTIONARY_DEFAULT))
def test_assumed_feature(self): tests = [ ('dictionary-required', 'dictionary', 'dictionary-default'), ] for feature, expected, not_added in tests: options = parser.Options(feature) self.assertTrue(options.has_feature(feature)) self.assertTrue(options.has_feature(expected)) self.assertFalse(options.has_feature(not_added))
def test_enforces_options(self): tests = [ (['dictionary'], 'dictionary Foo { long x; };'), (['dictionary-required'], 'dictionary Foo { required long x; };'), (['dictionary-default'], 'dictionary Foo { long x = 123; };'), ] parse = parser.IdlParser() for config, code in tests: # With all options it should work. parse.options = parser.Options.all() parse.parse('', code) # It should also work with just the setting given. parse.options = parser.Options(*config) parse.parse('', code) # Without setting given, should raise an error. with self.assertRaises(parser.IdlSyntaxError): parse.options = parser.Options() parse.parse('', code)