From: "Devan Franchini" <twitch153@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/webapp-config:experimental commit in: WebappConfig/tests/, WebappConfig/
Date: Fri, 19 Jun 2015 19:19:28 +0000 (UTC) [thread overview]
Message-ID: <1434741554.e1fdc8fadbe900f40b0ea99a95ff94ac08827636.twitch153@gentoo> (raw)
commit: e1fdc8fadbe900f40b0ea99a95ff94ac08827636
Author: Devan Franchini <twitch153 <AT> gentoo <DOT> org>
AuthorDate: Sun Nov 2 08:15:18 2014 +0000
Commit: Devan Franchini <twitch153 <AT> gentoo <DOT> org>
CommitDate: Fri Jun 19 19:19:14 2015 +0000
URL: https://gitweb.gentoo.org/proj/webapp-config.git/commit/?id=e1fdc8fa
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 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)
next reply other threads:[~2015-06-19 19:19 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-19 19:19 Devan Franchini [this message]
-- strict thread matches above, loose matches on Subject: below --
2014-11-17 23:58 [gentoo-commits] proj/webapp-config:experimental commit in: WebappConfig/tests/, WebappConfig/ Devan Franchini
2014-11-17 23:58 Devan Franchini
2014-11-17 23:58 Devan Franchini
2014-11-17 23:58 Devan Franchini
2014-11-17 23:42 Devan Franchini
2014-11-17 23:42 Devan Franchini
2014-11-17 23:42 Devan Franchini
2014-11-17 23:42 Devan Franchini
2014-11-17 23:42 Devan Franchini
2014-11-17 23:42 Devan Franchini
2014-11-03 0:02 Devan Franchini
2014-11-03 0:02 Devan Franchini
2014-11-02 8:27 Devan Franchini
2014-11-02 7:37 Devan Franchini
2014-11-02 7:37 Devan Franchini
2014-11-02 5:58 Devan Franchini
2014-11-02 5:58 Devan Franchini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1434741554.e1fdc8fadbe900f40b0ea99a95ff94ac08827636.twitch153@gentoo \
--to=twitch153@gentoo.org \
--cc=gentoo-commits@lists.gentoo.org \
--cc=gentoo-dev@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox