From 095fbdaf8d165dae390c4fb61b888309056b8fe6 Mon Sep 17 00:00:00 2001 From: Brett Smith Date: Sun, 25 Mar 2012 12:11:13 -0400 Subject: 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. --- mediagoblin/tests/test_processing.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 mediagoblin/tests/test_processing.py (limited to 'mediagoblin/tests/test_processing.py') diff --git a/mediagoblin/tests/test_processing.py b/mediagoblin/tests/test_processing.py new file mode 100644 index 00000000..6f3fad70 --- /dev/null +++ b/mediagoblin/tests/test_processing.py @@ -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)) -- cgit v1.2.3 From 28f364bd6d488955952aebe86033e5ba148da2fb Mon Sep 17 00:00:00 2001 From: Brett Smith Date: Mon, 26 Mar 2012 13:40:35 -0400 Subject: Rename to FilenameBuilder, with a main method named fill. I think these names better convey what's actually going on. I updated the documentation a bit while I was at it. --- mediagoblin/tests/test_processing.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'mediagoblin/tests/test_processing.py') diff --git a/mediagoblin/tests/test_processing.py b/mediagoblin/tests/test_processing.py index 6f3fad70..417f91f3 100644 --- a/mediagoblin/tests/test_processing.py +++ b/mediagoblin/tests/test_processing.py @@ -5,16 +5,16 @@ 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) + def run_fill(self, input, format, output=None): + builder = processing.FilenameBuilder(input) + result = builder.fill(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_easy_filename_fill(self): + self.run_fill('/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)) + def test_long_filename_fill(self): + self.run_fill('{0}.png'.format('A' * 300), 'image-{basename}{ext}', + 'image-{0}.png'.format('A' * 245)) -- cgit v1.2.3