Commit 83feff56 authored by Ezio Melotti's avatar Ezio Melotti

#6484: refactor a bit the tests.

parent 91f948a7
...@@ -9,35 +9,47 @@ MAILCAPFILE = test.support.findfile("mailcap.txt") ...@@ -9,35 +9,47 @@ MAILCAPFILE = test.support.findfile("mailcap.txt")
# Dict to act as mock mailcap entry for this test # Dict to act as mock mailcap entry for this test
# The keys and values should match the contents of MAILCAPFILE # The keys and values should match the contents of MAILCAPFILE
MAILCAPDICT = {'application/x-movie': [{'compose': 'moviemaker %s', MAILCAPDICT = {
'application/x-movie':
[{'compose': 'moviemaker %s',
'x11-bitmap': '"/usr/lib/Zmail/bitmaps/movie.xbm"', 'x11-bitmap': '"/usr/lib/Zmail/bitmaps/movie.xbm"',
'description': '"Movie"', 'description': '"Movie"',
'view': 'movieplayer %s'}], 'view': 'movieplayer %s'}],
'application/*': [{'copiousoutput': '', 'application/*':
[{'copiousoutput': '',
'view': 'echo "This is \\"%t\\" but is 50 \\% Greek to me" \\; cat %s'}], 'view': 'echo "This is \\"%t\\" but is 50 \\% Greek to me" \\; cat %s'}],
'audio/basic': [{'edit': 'audiocompose %s', 'audio/basic':
[{'edit': 'audiocompose %s',
'compose': 'audiocompose %s', 'compose': 'audiocompose %s',
'description': '"An audio fragment"', 'description': '"An audio fragment"',
'view': 'showaudio %s'}], 'view': 'showaudio %s'}],
'video/mpeg': [{'view': 'mpeg_play %s'}], 'video/mpeg':
'application/postscript': [{'needsterminal': '', [{'view': 'mpeg_play %s'}],
'view': 'ps-to-terminal %s'}, 'application/postscript':
{'compose': 'idraw %s', [{'needsterminal': '', 'view': 'ps-to-terminal %s'},
'view': 'ps-to-terminal %s'}], {'compose': 'idraw %s', 'view': 'ps-to-terminal %s'}],
'application/x-dvi': [{'view': 'xdvi %s'}], 'application/x-dvi':
'message/external-body': [{'composetyped': 'extcompose %s', [{'view': 'xdvi %s'}],
'message/external-body':
[{'composetyped': 'extcompose %s',
'description': '"A reference to data stored in an external location"', 'description': '"A reference to data stored in an external location"',
'needsterminal': '', 'needsterminal': '',
'view': 'showexternal %s %{access-type} %{name} %{site} %{directory} %{mode} %{server}'}], 'view': 'showexternal %s %{access-type} %{name} %{site} %{directory} %{mode} %{server}'}],
'text/richtext': [{'test': 'test "`echo %{charset} | tr \'[A-Z]\' \'[a-z]\'`" = iso-8859-8', 'text/richtext':
[{'test': 'test "`echo %{charset} | tr \'[A-Z]\' \'[a-z]\'`" = iso-8859-8',
'copiousoutput': '', 'copiousoutput': '',
'view': 'shownonascii iso-8859-8 -e richtext -p %s'}], 'view': 'shownonascii iso-8859-8 -e richtext -p %s'}],
'image/x-xwindowdump': [{'view': 'display %s'}], 'image/x-xwindowdump':
'audio/*': [{'view': '/usr/local/bin/showaudio %t'}], [{'view': 'display %s'}],
'video/*': [{'view': 'animate %s'}], 'audio/*':
'application/frame': [{'print': '"cat %s | lp"', [{'view': '/usr/local/bin/showaudio %t'}],
'view': 'showframe %s'}], 'video/*':
'image/rgb': [{'view': 'display %s'}]} [{'view': 'animate %s'}],
'application/frame':
[{'print': '"cat %s | lp"', 'view': 'showframe %s'}],
'image/rgb':
[{'view': 'display %s'}]
}
class HelperFunctionTest(unittest.TestCase): class HelperFunctionTest(unittest.TestCase):
...@@ -47,8 +59,9 @@ class HelperFunctionTest(unittest.TestCase): ...@@ -47,8 +59,9 @@ class HelperFunctionTest(unittest.TestCase):
# So verify that listmailcapfiles() returns a list of strings that is of # So verify that listmailcapfiles() returns a list of strings that is of
# non-zero length. # non-zero length.
mcfiles = mailcap.listmailcapfiles() mcfiles = mailcap.listmailcapfiles()
self.assertTrue(isinstance(mcfiles, list)) self.assertIsInstance(mcfiles, list)
self.assertTrue(all([isinstance(m, str) for m in mcfiles])) for m in mcfiles:
self.assertIsInstance(m, str)
with test.support.EnvironmentVarGuard() as env: with test.support.EnvironmentVarGuard() as env:
# According to RFC 1524, if MAILCAPS env variable exists, use that # According to RFC 1524, if MAILCAPS env variable exists, use that
# and only that. # and only that.
...@@ -111,15 +124,16 @@ class GetcapsTest(unittest.TestCase): ...@@ -111,15 +124,16 @@ class GetcapsTest(unittest.TestCase):
def test_system_mailcap(self): def test_system_mailcap(self):
# Test mailcap.getcaps() with mailcap file(s) on system, if any. # Test mailcap.getcaps() with mailcap file(s) on system, if any.
caps = mailcap.getcaps() caps = mailcap.getcaps()
self.assertTrue(isinstance(caps, dict)) self.assertIsInstance(caps, dict)
mailcapfiles = mailcap.listmailcapfiles() mailcapfiles = mailcap.listmailcapfiles()
existingmcfiles = [mcf for mcf in mailcapfiles if os.path.exists(mcf)] existingmcfiles = [mcf for mcf in mailcapfiles if os.path.exists(mcf)]
if existingmcfiles: if existingmcfiles:
# At least 1 mailcap file exists, so test that. # At least 1 mailcap file exists, so test that.
for (k, v) in caps.items(): for (k, v) in caps.items():
self.assertTrue(isinstance(k, str)) self.assertIsInstance(k, str)
self.assertTrue(isinstance(v, list)) self.assertIsInstance(v, list)
self.assertTrue(all([isinstance(e, dict) for e in v])) for e in v:
self.assertIsInstance(e, dict)
else: else:
# No mailcap files on system. getcaps() should return empty dict. # No mailcap files on system. getcaps() should return empty dict.
self.assertEqual({}, caps) self.assertEqual({}, caps)
...@@ -134,15 +148,19 @@ class FindmatchTest(unittest.TestCase): ...@@ -134,15 +148,19 @@ class FindmatchTest(unittest.TestCase):
fname = "foo.txt" fname = "foo.txt"
plist = ["access-type=default", "name=john", "site=python.org", plist = ["access-type=default", "name=john", "site=python.org",
"directory=/tmp", "mode=foo", "server=bar"] "directory=/tmp", "mode=foo", "server=bar"]
audio_basic_entry = {'edit': 'audiocompose %s', audio_basic_entry = {
'edit': 'audiocompose %s',
'compose': 'audiocompose %s', 'compose': 'audiocompose %s',
'description': '"An audio fragment"', 'description': '"An audio fragment"',
'view': 'showaudio %s'} 'view': 'showaudio %s'
}
audio_entry = {"view": "/usr/local/bin/showaudio %t"} audio_entry = {"view": "/usr/local/bin/showaudio %t"}
video_entry = {'view': 'animate %s'} video_entry = {'view': 'animate %s'}
message_entry = {'composetyped': 'extcompose %s', message_entry = {
'composetyped': 'extcompose %s',
'description': '"A reference to data stored in an external location"', 'needsterminal': '', 'description': '"A reference to data stored in an external location"', 'needsterminal': '',
'view': 'showexternal %s %{access-type} %{name} %{site} %{directory} %{mode} %{server}'} 'view': 'showexternal %s %{access-type} %{name} %{site} %{directory} %{mode} %{server}'
}
# test case: (findmatch args, findmatch keyword args, expected output) # test case: (findmatch args, findmatch keyword args, expected output)
# positional args: caps, MIMEtype # positional args: caps, MIMEtype
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment