diff options
author | Devan Franchini <twitch153@gentoo.org> | 2014-11-02 03:15:18 -0500 |
---|---|---|
committer | Devan Franchini <twitch153@gentoo.org> | 2015-06-19 15:48:55 -0400 |
commit | 15149d31eaaca1a97c83adc437505210bfdd467c (patch) | |
tree | d80c18df54ab8dd4d154859916a241eac61876e3 | |
parent | Adds Ebuild tests to external test suite (diff) | |
download | webapp-config-15149d31eaaca1a97c83adc437505210bfdd467c.tar.gz webapp-config-15149d31eaaca1a97c83adc437505210bfdd467c.tar.bz2 webapp-config-15149d31eaaca1a97c83adc437505210bfdd467c.zip |
Adds FileType tests to external test suite
tests/dtest.py: Removes WebappConfig.filetype from doctest listing
tests/external.py: Adds tests for FileType class
filetype.py: Removes doctests
-rw-r--r-- | WebappConfig/filetype.py | 79 | ||||
-rw-r--r-- | WebappConfig/tests/dtest.py | 2 | ||||
-rwxr-xr-x | WebappConfig/tests/external.py | 37 |
3 files changed, 37 insertions, 81 deletions
diff --git a/WebappConfig/filetype.py b/WebappConfig/filetype.py index 63d7e5f..d677189 100644 --- a/WebappConfig/filetype.py +++ b/WebappConfig/filetype.py @@ -36,80 +36,6 @@ class FileType: - a list of all files and directories owned by the config user - a list of all files and directories owned by the server user - - This creates such lists: - - >>> config_owned = [ 'a', 'a/b/c/d', '/e', '/f/', '/g/h/', 'i\\n'] - >>> server_owned = [ 'j', 'k/l/m/n', '/o', '/p/', '/q/r/', 's\\n'] - - The class is initialized with these two arrays: - - >>> a = FileType(config_owned, server_owned) - - This class provides three functions to retrieve information about - the file or directory type. - - File types - ---------- - - >>> a.filetype('a') - 'config-owned' - >>> a.filetype('a/b/c/d') - 'config-owned' - - >>> a.filetype('j') - 'server-owned' - >>> a.filetype('/o') - 'server-owned' - - File names - whether specified as input in the - {config,server}_owned lists or as key for retrieving the type - may - have leading or trailing whitespace. It will be removed. Trailing - - >>> a.filetype('\\n s') - 'server-owned' - >>> a.filetype('/g/h\\n') - 'config-owned' - - Unspecified files will result in a virtual type: - - >>> a.filetype('unspecified.txt') - 'virtual' - - This behaviour can be influenced by setting the 'virtual_files' - option for the class (which corresponds to the --virtual-files command - line option): - - >>> b = FileType(config_owned, server_owned, - ... virtual_files = 'server-owned') - >>> b.filetype('unspecified.txt') - 'server-owned' - - Directory types - --------------- - - The class does not know if the given keys are files or directories. - This is specified using the correct function for them. So the same - keys that were used above can also be used here: - - >>> a.dirtype('a') - 'config-owned' - >>> a.dirtype('j') - 'server-owned' - - The same whitespace and trailing slash fixing rules apply for - directory names: - - >>> a.dirtype('\\n s') - 'server-owned' - >>> a.dirtype('/g/h\\n') - 'config-owned' - - Unspecified directories are 'default-owned' and not marked 'virtual': - - >>> a.dirtype('unspecified.txt') - 'default-owned' - ''' def __init__(self, @@ -224,8 +150,3 @@ class FileType: filename = re.compile('/+').sub('/', filename) return filename - - -if __name__ == '__main__': - import doctest, sys - doctest.testmod(sys.modules[__name__]) diff --git a/WebappConfig/tests/dtest.py b/WebappConfig/tests/dtest.py index a46be2c..bfb82fa 100644 --- a/WebappConfig/tests/dtest.py +++ b/WebappConfig/tests/dtest.py @@ -8,13 +8,11 @@ import unittest, doctest, sys -import WebappConfig.filetype import WebappConfig.protect import WebappConfig.worker def test_suite(): return unittest.TestSuite(( - doctest.DocTestSuite(WebappConfig.filetype), doctest.DocTestSuite(WebappConfig.protect), doctest.DocTestSuite(WebappConfig.worker), )) diff --git a/WebappConfig/tests/external.py b/WebappConfig/tests/external.py index 88b98c8..c8b0646 100755 --- a/WebappConfig/tests/external.py +++ b/WebappConfig/tests/external.py @@ -28,6 +28,7 @@ from WebappConfig.db import WebappDB, WebappSource from WebappConfig.debug import OUT from WebappConfig.dotconfig import DotConfig from WebappConfig.ebuild import Ebuild +from WebappConfig.filetype import FileType from WebappConfig.server import Basic from warnings import filterwarnings, resetwarnings @@ -329,6 +330,42 @@ class EbuildTest(unittest.TestCase): 'hostroot'))) +class FileTypeTest(unittest.TestCase): + def test_filetypes(self): + config_owned = ('a', 'a/b/c/d', '/e', '/f/', '/g/h/', 'i\\n') + server_owned = ('j', 'k/l/m/n', '/o', '/p/', '/q/r/', 's\\n') + + types = FileType(config_owned, server_owned) + + self.assertEqual(types.filetype('a'), 'config-owned') + self.assertEqual(types.filetype('a/b/c/d'), 'config-owned') + self.assertEqual(types.filetype('j'), 'server-owned') + self.assertEqual(types.filetype('/o'), 'server-owned') + + # It will always remove leading spaces or whitespace: + self.assertEqual(types.filetype('\t s\\n'), 'server-owned') + # Unspecified files will be set as virtual: + self.assertEqual(types.filetype('foo.txt'), 'virtual') + # However, you can set what you want your virtual-files to be: + types = FileType(config_owned, server_owned, + virtual_files='server-owned') + self.assertEqual(types.filetype('foo.txt'), 'server-owned') + + def test_dirtypes(self): + config_owned = ('a', 'a/b/c/d', '/e', '/f/', '/g/h/', 'i\\n') + server_owned = ('j', 'k/l/m/n', '/o', '/p/', '/q/r/', 's\\n') + + types = FileType(config_owned, server_owned) + + self.assertEqual(types.dirtype('a'), 'config-owned') + self.assertEqual(types.dirtype('j'), 'server-owned') + + # Same whitespace rules apply for dirtype(): + self.assertEqual(types.dirtype('\t s\\n'), 'server-owned') + # Unspecified dirs will be set as default-owned: + self.assertEqual(types.dirtype('foo.txt'), 'default-owned') + + if __name__ == '__main__': filterwarnings('ignore') unittest.main(module=__name__, buffer=True) |