diff options
author | Nikolaus Schulz <microschulz@web.de> | 2010-07-30 23:26:22 +0200 |
---|---|---|
committer | Nikolaus Schulz <microschulz@web.de> | 2010-07-31 20:49:03 +0200 |
commit | b6bc92c34f255054a7fd2128a024a5ae26cd1026 (patch) | |
tree | ac3268c8f698f38d866ce164ad3c3d62b86a678c /test_archivemail | |
parent | f22fe4decd9a70a2eb826ecdd14f9d1bb3b4e394 (diff) | |
download | archivemail-b6bc92c34f255054a7fd2128a024a5ae26cd1026.tar.gz archivemail-b6bc92c34f255054a7fd2128a024a5ae26cd1026.tar.bz2 archivemail-b6bc92c34f255054a7fd2128a024a5ae26cd1026.zip |
New option --archive-prefix, alias -p
Technically, this works just like the --suffix option. This commit also
updates the manpage accordingly.
Currently, the prefix is not checked for slashes, so it could contain path
components. (The same applies for the suffix, btw). Since the expanded
string is prepended to the archive base name, this can be used to dynamically
configure the archive directory, depending on the archive cutoff date. I'm
not sure if this can be considered a reasonable feature, though.
Diffstat (limited to 'test_archivemail')
-rwxr-xr-x | test_archivemail | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/test_archivemail b/test_archivemail index fda2d63..406a3b4 100755 --- a/test_archivemail +++ b/test_archivemail @@ -425,6 +425,15 @@ class TestOptionParser(unittest.TestCase): archivemail.options.parse_args(["-s", suffix], "") assert archivemail.options.archive_suffix == suffix + def testOptionPrefix(self): + """--prefix and -p options are parsed correctly""" + for prefix in ("_static_", "_%B_%Y", "-%Y-%m-%d"): + archivemail.options.parse_args(["--prefix="+prefix], "") + assert archivemail.options.archive_prefix == prefix + archivemail.options.prefix = None + archivemail.options.parse_args(["-p", prefix], "") + assert archivemail.options.archive_prefix == prefix + def testOptionDryrun(self): """--dry-run option is parsed correctly""" archivemail.options.parse_args(["--dry-run"], "") @@ -908,6 +917,31 @@ class TestArchiveMboxSuffix(unittest.TestCase): archivemail.options.quiet = False archivemail.options.archive_suffix = self.old_suffix +class TestArchiveMboxPrefix(unittest.TestCase): + """make sure the 'prefix' option works""" + def setUp(self): + self.old_prefix = archivemail.options.archive_prefix + self.old_suffix = archivemail.options.archive_suffix + archivemail.options.archive_suffix = "" + archivemail.options.quiet = True + + def testPrefix(self): + """archiving with specified --prefix arguments""" + for archive_prefix in ("_static_", "_%B_%Y", "-%Y-%m-%d", "%Y/%m/"): + archivemail.options.archive_prefix = archive_prefix + for mbox_name in "foobar", "/tmp/foobar", "schnorchz/foobar": + archive_dir, archive_base = os.path.split(mbox_name) + days = archivemail.options.days_old_max + tm = time.localtime(time.time() - days*24*60*60) + prefix = time.strftime(archive_prefix, tm) + archive_name = os.path.join(archive_dir, prefix + archive_base) + self.assertEqual(archive_name, + archivemail.make_archive_name(mbox_name)) + + def tearDown(self): + archivemail.options.quiet = False + archivemail.options.archive_prefix = self.old_prefix + archivemail.options.archive_suffix = self.old_suffix class TestArchiveDryRun(TestArchive): """make sure the 'dry-run' option works""" |