Write a test for builds() check

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2013-05-13 18:44:50 +02:00
parent 4d625fff20
commit 66e5af4a82
2 changed files with 14 additions and 4 deletions

View File

@ -97,7 +97,7 @@ def builds(_type):
unpythonic_chars = ["-"]
really_ok = ["-"]
if True in (x in str_type(_type) for x in unpythonic_chars):
if any(x in unpythonic_chars for x in str_type(_type)):
if _type not in really_ok:
raise TypeError("`build' needs to be *post* translated strings, "
"Mr. / Mrs. Hypser. -- `%s' sucks." % (_type))

View File

@ -27,11 +27,21 @@ if sys.version_info[0] <= 2 and sys.version_info[1] <= 6:
else:
import unittest
from hy import compiler
from hy.models.expression import HyExpression
from hy.models.list import HyList
from hy.models.symbol import HySymbol
from hy.compiler import HyASTCompiler
class CompilerTest(unittest.TestCase):
def test_builds_with_dash(self):
self.assert_(callable(compiler.builds("foobar")))
self.assert_(callable(compiler.builds("foo_bar")))
self.assert_(callable(compiler.builds("-")))
self.assertRaisesRegexp(TypeError,
"\*post\* translated strings",
compiler.builds, "foobar-with-dash-")
class HyASTCompilerTest(unittest.TestCase):
@ -46,7 +56,7 @@ class HyASTCompilerTest(unittest.TestCase):
return h
def setUp(self):
self.c = HyASTCompiler()
self.c = compiler.HyASTCompiler()
def test_fn_compiler_empty_function(self):
ret = self.c.compile_function_def(