Ejemplo n.º 1
0
 def test_parsing(self):
     """pathrender: pattern parsing"""
     pattern = Pattern(u"{$Disc.}$Track - $Artist - $Title{ [$Year]}")
     expected = [
         _pr._OptionalBlock(
             [_pr._Replacement(u"$Disc"),
              _pr._LiteralText(u".")]),
         _pr._Replacement(u"$Track"),
         _pr._LiteralText(u" - "),
         _pr._Replacement(u"$Artist"),
         _pr._LiteralText(u" - "),
         _pr._Replacement(u"$Title"),
         _pr._OptionalBlock([
             _pr._LiteralText(u" ["),
             _pr._Replacement(u"$Year"),
             _pr._LiteralText(u"]")
         ])
     ]
     self.assertEqual(expected, pattern._pattern)
     self.assertItemsEqual([], pattern.warnings)
Ejemplo n.º 2
0
 def test_parsing(self):
     """pathrender: pattern parsing"""
     pattern = Pattern(u"{$Disc.}$Track - $Artist - $Title{ [$Year]}")
     expected = [
         _pr._OptionalBlock([
             _pr._Replacement(u"$Disc"),
             _pr._LiteralText(u".")
         ]),
         _pr._Replacement(u"$Track"),
         _pr._LiteralText(u" - "),
         _pr._Replacement(u"$Artist"),
         _pr._LiteralText(u" - "),
         _pr._Replacement(u"$Title"),
         _pr._OptionalBlock([
             _pr._LiteralText(u" ["),
             _pr._Replacement(u"$Year"),
             _pr._LiteralText(u"]")
         ])
     ]
     self.assertEqual(expected, pattern._pattern)
     self.assertItemsEqual([], pattern.warnings)
Ejemplo n.º 3
0
 def test_optional(self):
     """pathrender: _OptionalBlock element processing"""
     o = _pr._OptionalBlock(
         [_pr._Replacement(u"$Title"),
          _pr._LiteralText(u".foobar")])
     subst = {'$Title': 'foo', '$Track': 'bar'}
     res = o.render(subst)
     self.assertEqual(res, u'foo.foobar', 'check non-empty replacement')
     subst = {'$Title': ''}
     res = o.render(subst)
     self.assertEqual(res, '', 'check empty replacement')
     subst = {'$Title': None}
     res = o.render(subst)
     self.assertEqual(res, '', 'check render() works with None')
Ejemplo n.º 4
0
 def test_optional(self):
     """pathrender: _OptionalBlock element processing"""
     o = _pr._OptionalBlock([
         _pr._Replacement(u"$Title"),
         _pr._LiteralText(u".foobar")
     ])
     subst = {'$Title': 'foo', '$Track': 'bar'}
     res = o.render(subst)
     self.assertEqual(res, u'foo.foobar', 'check non-empty replacement')
     subst = {'$Title': ''}
     res = o.render(subst)
     self.assertEqual(res, '', 'check empty replacement')
     subst = {'$Title': None}
     res = o.render(subst)
     self.assertEqual(res, '', 'check render() works with None')