Add FilenameMunger class to processing, with tests.

Munging filenames is something all media type processors want to be able to
do, so I'm refactoring it out into a nice bite-sized class.
This commit is contained in:
Brett Smith
2012-03-25 12:11:13 -04:00
parent 6573573dd1
commit 095fbdaf8d
2 changed files with 36 additions and 0 deletions

View File

@@ -0,0 +1,20 @@
#!/usr/bin/env python
from nose.tools import assert_equal, assert_true, assert_false
from mediagoblin import processing
class TestProcessing(object):
def run_munge(self, input, format, output=None):
munger = processing.FilenameMunger(input)
result = munger.munge(format)
if output is None:
return result
assert_equal(output, result)
def test_easy_filename_munge(self):
self.run_munge('/home/user/foo.TXT', '{basename}bar{ext}', 'foobar.txt')
def test_long_filename_munge(self):
self.run_munge('{0}.png'.format('A' * 300), 'image-{basename}{ext}',
'image-{0}.png'.format('A' * 245))