Example #1
0
    def test_get_parser(self):
        fields = [
            'project', 'specification', 'descriptor', 'version', 'coordinate',
            'frame', 'extension'
        ]
        grammar = AssetNameParser._get_grammar()
        parser = AssetNameParser._get_parser(grammar, fields)

        expected = dict(project='proj001',
                        specification='spec002',
                        descriptor='desc',
                        version=3,
                        coordinate=[4, 5, 6],
                        frame=7,
                        extension='exr')
        name = 'p-proj001_s-spec002_d-desc_v003_c0004-0005-0006_f0007.exr'
        result = parser.parseString(name)[0].asDict()
        self.assertEqual(result, expected)

        name = 'p-proj001.s-spec002.d-desc.v003.c0004-0005-0006.f0007.exr'
        with self.assertRaises(ParseException):
            parser.parseString(name)[0].asDict()

        # no extension
        parser = AssetNameParser._get_parser(grammar, fields[:-1])
        del expected['extension']
        name = 'p-proj001_s-spec002_d-desc_v003_c0004-0005-0006_f0007'
        result = parser.parseString(name)[0].asDict()
        self.assertEqual(result, expected)

        name = 'p-proj001_s-spec002_d-desc_v003_c0004-0005-0006_f0007_exr'
        with self.assertRaises(ParseException):
            parser.parseString(name)[0].asDict()
Example #2
0
 def test_get_grammar(self):
     result = AssetNameParser._get_grammar()
     expected = [
         'project',
         'specification',
         'descriptor',
         'version',
         'coordinate',
         'frame',
         'extension',
         'field_separator',
     ]
     result = set(expected).difference(result.keys())
     self.assertEqual(len(result), 0)
Example #3
0
    def test_get_extension_parser(self):
        grammar = AssetNameParser._get_grammar()
        parser = AssetNameParser._get_extension_parser(grammar)

        expected = 'Illegal extension field token.*'
        with self.assertRaisesRegexp(ParseException, expected):
            parser.parseString('foo.')

        expected = 'Illegal extension field token.*'
        with self.assertRaisesRegexp(ParseException, expected):
            parser.parseString('foo.bar-baz')

        result = parser.parseString('foo.bar')[0].asDict()['extension']
        self.assertEqual(result, 'bar')

        result = parser.parseString('foo.bar.baz')[0].asDict()['extension']
        self.assertEqual(result, 'baz')

        result = parser.parseString('foo')[0].asDict()['extension']
        self.assertEqual(result, 'foo')

        result = parser.parseString('.foo')[0].asDict()['extension']
        self.assertEqual(result, 'foo')