added tests and refactored incorrect docstrings

This commit is contained in:
niphlod
2014-05-29 23:34:32 +02:00
parent 91d6834f0e
commit f1606ee091
4 changed files with 61 additions and 13 deletions
+10 -9
View File
@@ -558,18 +558,19 @@ class translator(object):
self.force(self.http_accept_language) self.force(self.http_accept_language)
def plural(self, word, n): def plural(self, word, n):
""" Gets plural form of word for number *n* """
invoked from T()/T.M() in `%%{}` tag Gets plural form of word for number *n*
invoked from T()/T.M() in `%%{}` tag
Args: Note:
word (str): word in singular "word" MUST be defined in current language (T.accepted_language)
n (numeric): number plural form created for
Returns: Args:
word (str): word in appropriate singular/plural form word (str): word in singular
n (numeric): number plural form created for
Note: Returns:
"word" MUST be defined in current language (T.accepted_language) word (str): word in appropriate singular/plural form
""" """
if int(n) == 1: if int(n) == 1:
+2 -1
View File
@@ -197,8 +197,9 @@ class RestrictedError(Exception):
def compile2(code, layer): def compile2(code, layer):
""" """
The +'\n' is necessary else compile fails when code ends in a comment. The ``+'\\n'`` is necessary else compile fails when code ends in a comment.
""" """
return compile(code.rstrip().replace('\r\n', '\n') + '\n', layer, 'exec') return compile(code.rstrip().replace('\r\n', '\n') + '\n', layer, 'exec')
+40
View File
@@ -38,6 +38,7 @@ def fix_sys_path():
fix_sys_path() fix_sys_path()
from html import * from html import *
from storage import Storage
class TestBareHelpers(unittest.TestCase): class TestBareHelpers(unittest.TestCase):
@@ -276,6 +277,45 @@ class TestBareHelpers(unittest.TestCase):
self.assertEqual(UL('<>', _a='1', _b='2').xml(), self.assertEqual(UL('<>', _a='1', _b='2').xml(),
'<ul a="1" b="2"><li>&lt;&gt;</li></ul>') '<ul a="1" b="2"><li>&lt;&gt;</li></ul>')
def testStaticURL(self):
# test response.static_version coupled with response.static_version_urls
self.assertEqual(URL('a', 'c', 'f'), '/a/c/f')
self.assertEqual(URL('a', 'static', 'design.css'), '/a/static/design.css')
response = Storage()
response.static_version = '1.2.3'
from globals import current
current.response = response
self.assertEqual(URL('a', 'static', 'design.css'), '/a/static/design.css')
response.static_version_urls = True
self.assertEqual(URL('a', 'static', 'design.css'), '/a/static/_1.2.3/design.css')
def testURL(self):
self.assertEqual(URL('a', 'c', 'f', args='1'), '/a/c/f/1')
self.assertEqual(URL('a', 'c', 'f', args=('1', '2')), '/a/c/f/1/2')
self.assertEqual(URL('a', 'c', 'f', args=['1', '2']), '/a/c/f/1/2')
self.assertEqual(URL('a', 'c', '/f'), '/a/c/f')
self.assertEqual(URL('a', 'c', 'f.json'), '/a/c/f.json')
self.assertRaises(SyntaxError, URL, *['a'])
request = Storage()
request.application = 'a'
request.controller = 'c'
request.function = 'f'
request.env = {}
from globals import current
current.request = request
must_return = '/a/c/f'
self.assertEqual(URL('f'), must_return)
self.assertEqual(URL('c', 'f'), must_return)
self.assertEqual(URL('a', 'c', 'f'), must_return)
self.assertEqual(URL('a', 'c', 'f', extension='json'), '/a/c/f.json')
def weird():
pass
self.assertEqual(URL('a', 'c', weird), '/a/c/weird')
self.assertRaises(SyntaxError, URL, *['a','c', 1])
class TestData(unittest.TestCase): class TestData(unittest.TestCase):
def testAdata(self): def testAdata(self):
+6
View File
@@ -63,6 +63,12 @@ def startwebserver():
for a in range(1,11): for a in range(1,11):
time.sleep(1) time.sleep(1)
print a, '...' print a, '...'
try:
c = WebClient('http://127.0.0.1:8000')
c.get('/')
break
except:
continue
print '' print ''
def terminate_process(pid): def terminate_process(pid):