From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id E50F1138AEC for ; Sun, 2 Nov 2014 08:27:19 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 64922E0C75; Sun, 2 Nov 2014 08:27:19 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id D32A7E0C75 for ; Sun, 2 Nov 2014 08:27:18 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 9B3AB340431 for ; Sun, 2 Nov 2014 08:27:17 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 4757A9442 for ; Sun, 2 Nov 2014 08:27:16 +0000 (UTC) From: "Devan Franchini" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Devan Franchini" Message-ID: <1414916737.161b1cc82ccbdf848bb9a41594e65ac9e3d2b0f2.twitch153@gentoo> Subject: [gentoo-commits] proj/webapp-config:experimental commit in: WebappConfig/tests/, WebappConfig/ X-VCS-Repository: proj/webapp-config X-VCS-Files: WebappConfig/filetype.py WebappConfig/tests/dtest.py WebappConfig/tests/external.py X-VCS-Directories: WebappConfig/ WebappConfig/tests/ X-VCS-Committer: twitch153 X-VCS-Committer-Name: Devan Franchini X-VCS-Revision: 161b1cc82ccbdf848bb9a41594e65ac9e3d2b0f2 X-VCS-Branch: experimental Date: Sun, 2 Nov 2014 08:27:16 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 871db749-f572-4ddc-b139-fbf3e117d9a5 X-Archives-Hash: ce45fbd2f24cca8225613e044e38956e commit: 161b1cc82ccbdf848bb9a41594e65ac9e3d2b0f2 Author: Devan Franchini gentoo org> AuthorDate: Sun Nov 2 08:15:18 2014 +0000 Commit: Devan Franchini gentoo org> CommitDate: Sun Nov 2 08:25:37 2014 +0000 URL: http://sources.gentoo.org/gitweb/?p=proj/webapp-config.git;a=commit;h=161b1cc8 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 --- WebappConfig/filetype.py | 79 ------------------------------------------ WebappConfig/tests/dtest.py | 2 -- 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 5035c06..86afe18 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 @@ -334,6 +335,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)