Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Beefing up XHPy tests

This is the beginning of a quick effort to make these tests quickly
runnable by putting them under Python's unittest framework. Once that's
done, moving forward all commits will be covered by a pre-commit hook
that runs these tests.
  • Loading branch information...
commit aa78dfc4079c3a2b39e6d6be842038a20210f337 1 parent a90512c
@candu authored
Showing with 184 additions and 59 deletions.
  1. +1 −1  .gitignore
  2. +4 −0 xhpy/parser.py
  3. +1 −1  xhpy/tests/full/array_constant.py
  4. +1 −1  xhpy/tests/full/attr_blank.py
  5. +1 −1  xhpy/tests/full/attr_entity.py
  6. +1 −1  xhpy/tests/full/attr_float.py
  7. +1 −1  xhpy/tests/full/attributes.py
  8. +1 −2  xhpy/tests/full/class_constants.py
  9. +1 −1  xhpy/tests/full/docstrings_01.py
  10. +1 −1  xhpy/tests/full/docstrings_02.py
  11. +1 −1  xhpy/tests/full/docstrings_03.py
  12. +1 −1  xhpy/tests/full/docstrings_05.py
  13. +1 −1  xhpy/tests/full/klass.py
  14. +1 −1  xhpy/tests/full/lineno_01.py
  15. +1 −1  xhpy/tests/full/logical_op.py
  16. +1 −1  xhpy/tests/full/pep0263_01.py
  17. +1 −1  xhpy/tests/full/pep0263_02.py
  18. +1 −1  xhpy/tests/full/pep0263_03.py
  19. +142 −27 xhpy/tests/full/run_tests
  20. +1 −1  xhpy/tests/full/stack_balance_fail.py
  21. +1 −1  xhpy/tests/full/whitespace_01.py
  22. +1 −1  xhpy/tests/full/whitespace_02.py
  23. +1 −1  xhpy/tests/full/whitespace_03.py
  24. +1 −1  xhpy/tests/full/whitespace_04.py
  25. +1 −1  xhpy/tests/full/whitespace_05.py
  26. +1 −1  xhpy/tests/full/whitespace_06.py
  27. +1 −1  xhpy/tests/full/whitespace_07.py
  28. +1 −1  xhpy/tests/full/xhpy_function_param.py
  29. +4 −0 xhpy/tests/precompiled/cleanup_tests
  30. +1 −0  xhpy/tests/precompiled/run_tests
  31. +5 −3 xhpy/tests/precompiled/setup_tests
  32. +2 −2 xhpy/tests/precompiled/tests/test.py.in
View
2  .gitignore
@@ -2,5 +2,5 @@
*.pyc
MANIFEST
dist/
-xhpy/tests/precompiled/pylib/
+xhpy/tests/precompiled/xhpy_precompiled
xhpy/tests/precompiled/*.py
View
4 xhpy/parser.py
@@ -11,6 +11,10 @@
tokenize.untokenize to produce Python output.
"""
+if __package__ is None:
+ import xhpy
+ __package__ = 'xhpy'
+
from .constants import *
from .utils import tag2class
View
2  xhpy/tests/full/array_constant.py
@@ -2,4 +2,4 @@
class :foo(object):
bar = 'pass'
foo = {'etc': :foo.bar}
-print foo['etc']
+result = foo['etc']
View
2  xhpy/tests/full/attr_blank.py
@@ -2,4 +2,4 @@ class xhpy_a:
def __init__(self, _1={}, _2=[]):
pass
foo = <a b="" />
-print "pass"
+result = "pass"
View
2  xhpy/tests/full/attr_entity.py
@@ -2,4 +2,4 @@ class xhpy_a:
def __init__(self, _1={}, _2=[]):
pass
foo = <a b="&snowman;">c</a>
-print "pass"
+result = "pass"
View
2  xhpy/tests/full/attr_float.py
@@ -3,4 +3,4 @@ class :foo(object):
def __init__(self):
pass
-print "pass"
+result = "pass"
View
2  xhpy/tests/full/attributes.py
@@ -10,4 +10,4 @@ class :bar(object):
string bar
def __init__(self):
pass
-print "pass"
+result = "pass"
View
3  xhpy/tests/full/class_constants.py
@@ -2,5 +2,4 @@ class :foo(object):
bar = None
etc = 1
:foo.bar = 2
-print :foo.etc
-print :foo.bar
+result = {'etc': :foo.etc, 'bar': :foo.bar}
View
2  xhpy/tests/full/docstrings_01.py
@@ -3,5 +3,5 @@
def foo():
'b'
pass
-print foo.__doc__
+result = foo.__doc__
<a />
View
2  xhpy/tests/full/docstrings_02.py
@@ -3,5 +3,5 @@
class foo:
'b'
pass
-print foo.__doc__
+result = foo.__doc__
<a />
View
2  xhpy/tests/full/docstrings_03.py
@@ -5,5 +5,5 @@ class foo:
def bar(self):
'c'
pass
-print foo.bar.__doc__
+result = foo.bar.__doc__
<a />
View
2  xhpy/tests/full/docstrings_05.py
@@ -6,5 +6,5 @@ class foo:
bar = 1
def etc(self):
pass
-print foo.__doc__
+result = foo.__doc__
<a />
View
2  xhpy/tests/full/klass.py
@@ -4,4 +4,4 @@ class :x:foo(object):
pass
class :x:bar(:x:foo):
pass
-print "pass"
+result = "pass"
View
2  xhpy/tests/full/lineno_01.py
@@ -7,4 +7,4 @@ def method(self):
def foo():
pass
import inspect
-print inspect.getsourcelines(foo)
+result = inspect.getsourcelines(foo)
View
2  xhpy/tests/full/logical_op.py
@@ -1,3 +1,3 @@
-print True ^ False
+result = True ^ False
if 0:
<a />
View
2  xhpy/tests/full/pep0263_01.py
@@ -1,4 +1,4 @@
# coding=utf-8
from xhpy.pylib import *
name = u"André"
-print <p>{name}</p>
+result = <p>{name}</p>
View
2  xhpy/tests/full/pep0263_02.py
@@ -1,4 +1,4 @@
# -*- coding: utf-8 -*-
from xhpy.pylib import *
name = u"André"
-print <p>{name}</p>
+result = <p>{name}</p>
View
2  xhpy/tests/full/pep0263_03.py
@@ -1,4 +1,4 @@
# vim: set fileencoding=utf-8
from xhpy.pylib import *
name = u"André"
-print <p>{name}</p>
+result = <p>{name}</p>
View
169 xhpy/tests/full/run_tests
@@ -2,30 +2,145 @@
from xhpy.init import register_xhpy_module
-register_xhpy_module('array_constant'); import array_constant; print '[array_constant] DONE'
-register_xhpy_module('attr_blank'); import attr_blank; print '[attr_blank] DONE'
-register_xhpy_module('attr_entity'); import attr_entity; print '[attr_entity] DONE'
-register_xhpy_module('attr_float'); import attr_float; print '[attr_float] DONE'
-register_xhpy_module('attributes'); import attributes; print '[attributes] DONE'
-register_xhpy_module('class_constants'); import class_constants; print '[class_constants] DONE'
-register_xhpy_module('docstrings_01'); import docstrings_01; print '[docstrings_01] DONE'
-register_xhpy_module('docstrings_02'); import docstrings_02; print '[docstrings_02] DONE'
-register_xhpy_module('docstrings_03'); import docstrings_03; print '[docstrings_03] DONE'
-register_xhpy_module('docstrings_05'); import docstrings_05; print '[docstrings_05] DONE'
-register_xhpy_module('klass'); import klass; print '[klass] DONE'
-register_xhpy_module('lineno_01'); import lineno_01; print '[lineno_01] DONE'
-# TODO: add support for comment tokens within tags
-#register_xhpy_module('lineno_02'); import lineno_02; print '[lineno_02] DONE'
-register_xhpy_module('logical_op'); import logical_op; print '[logical_op] DONE'
-register_xhpy_module('pep0263_01'); import pep0263_01; print '[pep0263_01] DONE'
-register_xhpy_module('pep0263_02'); import pep0263_02; print '[pep0263_02] DONE'
-register_xhpy_module('pep0263_03'); import pep0263_03; print '[pep0263_03] DONE'
-register_xhpy_module('stack_balance_fail'); import stack_balance_fail; print '[stack_balance_fail] DONE'
-register_xhpy_module('whitespace_01'); import whitespace_01; print '[whitespace_01] DONE'
-register_xhpy_module('whitespace_02'); import whitespace_02; print '[whitespace_02] DONE'
-register_xhpy_module('whitespace_03'); import whitespace_03; print '[whitespace_03] DONE'
-register_xhpy_module('whitespace_04'); import whitespace_04; print '[whitespace_04] DONE'
-register_xhpy_module('whitespace_05'); import whitespace_05; print '[whitespace_05] DONE'
-register_xhpy_module('whitespace_06'); import whitespace_06; print '[whitespace_06] DONE'
-register_xhpy_module('whitespace_07'); import whitespace_07; print '[whitespace_07] DONE'
-register_xhpy_module('xhpy_function_param'); import xhpy_function_param; print '[xhpy_function_param] DONE'
+import unittest
+
+class XHPyFullTests(unittest.TestCase):
+ def test_array_constant(self):
+ register_xhpy_module('array_constant')
+ import array_constant
+ self.assertEqual('pass', array_constant.result)
+
+ def test_attr_blank(self):
+ register_xhpy_module('attr_blank')
+ import attr_blank
+ self.assertEqual('pass', attr_blank.result)
+
+ def test_attr_entity(self):
+ register_xhpy_module('attr_entity')
+ import attr_entity
+ self.assertEqual('pass', attr_entity.result)
+
+ def test_attr_float(self):
+ register_xhpy_module('attr_float')
+ import attr_float
+ self.assertEqual('pass', attr_float.result)
+
+ def test_attributes(self):
+ register_xhpy_module('attributes')
+ import attributes
+ self.assertEqual('pass', attributes.result)
+
+ def test_attributes(self):
+ register_xhpy_module('attributes')
+ import attributes
+ self.assertEqual('pass', attributes.result)
+
+ def test_class_constants(self):
+ register_xhpy_module('class_constants')
+ import class_constants
+ self.assertEqual({'etc': 1, 'bar': 2}, class_constants.result)
+
+ def test_docstrings_01(self):
+ register_xhpy_module('docstrings_01')
+ import docstrings_01
+ self.assertEqual('b', docstrings_01.result)
+
+ def test_docstrings_02(self):
+ register_xhpy_module('docstrings_02')
+ import docstrings_02
+ self.assertEqual('b', docstrings_02.result)
+
+ def test_docstrings_03(self):
+ register_xhpy_module('docstrings_03')
+ import docstrings_03
+ self.assertEqual('c', docstrings_03.result)
+
+ def test_docstrings_05(self):
+ register_xhpy_module('docstrings_05')
+ import docstrings_05
+ self.assertEqual('b', docstrings_05.result)
+
+ def test_klass(self):
+ register_xhpy_module('klass')
+ import klass
+ self.assertEqual('pass', klass.result)
+
+ @unittest.skip('TODO: match input source lines on output')
+ def test_lineno_01(self):
+ register_xhpy_module('lineno_01')
+ import lineno_01
+ self.assertEqual(7, lineno_01.result[1])
+
+ @unittest.skip('TODO: add support for comment tokens within tags')
+ def test_lineno_02(self):
+ register_xhpy_module('lineno_02')
+ import lineno_02
+ self.assertEqual(7, lineno_02.result[1])
+
+ def test_logical_op(self):
+ register_xhpy_module('logical_op')
+ import logical_op
+ self.assertEqual(True, logical_op.result)
+
+ def test_pep0263_01(self):
+ register_xhpy_module('pep0263_01')
+ import pep0263_01
+ self.assertEqual(u'<p>Andr\xe9</p>', unicode(pep0263_01.result))
+
+ def test_pep0263_02(self):
+ register_xhpy_module('pep0263_02')
+ import pep0263_02
+ self.assertEqual(u'<p>Andr\xe9</p>', unicode(pep0263_02.result))
+
+ def test_pep0263_03(self):
+ register_xhpy_module('pep0263_03')
+ import pep0263_03
+ self.assertEqual(u'<p>Andr\xe9</p>', unicode(pep0263_03.result))
+
+ def test_stack_balance_fail(self):
+ register_xhpy_module('stack_balance_fail')
+ import stack_balance_fail
+ self.assertEqual('pass', stack_balance_fail.result)
+
+ def test_whitespace_01(self):
+ register_xhpy_module('whitespace_01')
+ import whitespace_01
+ self.assertEqual(u'<a><a></a>+</a>', unicode(whitespace_01.result))
+
+ def test_whitespace_02(self):
+ register_xhpy_module('whitespace_02')
+ import whitespace_02
+ self.assertEqual(u'<a>a<a></a></a>', unicode(whitespace_02.result))
+
+ def test_whitespace_03(self):
+ register_xhpy_module('whitespace_03')
+ import whitespace_03
+ self.assertEqual(u'<a>a</a>', unicode(whitespace_03.result))
+
+ def test_whitespace_04(self):
+ register_xhpy_module('whitespace_04')
+ import whitespace_04
+ self.assertEqual(u'<a><a></a>a</a>', unicode(whitespace_04.result))
+
+ def test_whitespace_05(self):
+ register_xhpy_module('whitespace_05')
+ import whitespace_05
+ self.assertEqual(u'<a>foo</a>', unicode(whitespace_05.result))
+
+ def test_whitespace_06(self):
+ register_xhpy_module('whitespace_06')
+ import whitespace_06
+ self.assertEqual(u'<a>abc</a>', unicode(whitespace_06.result))
+
+ def test_whitespace_07(self):
+ register_xhpy_module('whitespace_07')
+ import whitespace_07
+ self.assertEqual(u'<a>abc</a>', unicode(whitespace_07.result))
+
+ def test_xhpy_function_param(self):
+ register_xhpy_module('xhpy_function_param')
+ import xhpy_function_param
+ self.assertEqual('pass', xhpy_function_param.result)
+
+if __name__ == '__main__':
+ unittest.main()
View
2  xhpy/tests/full/stack_balance_fail.py
@@ -5,4 +5,4 @@ def __init__(self, _1={}, _2=[]):
a = <x:y attr={CONSTANT} />
def f():
pass
-print 'pass'
+result = 'pass'
View
2  xhpy/tests/full/whitespace_01.py
@@ -1,5 +1,5 @@
from xhpy.pylib import *
-print <a>
+result = <a>
<a>
</a>+
</a>
View
2  xhpy/tests/full/whitespace_02.py
@@ -1,2 +1,2 @@
from xhpy.pylib import *
-print <a> {'a'}<a /></a>
+result = <a> {'a'}<a /></a>
View
2  xhpy/tests/full/whitespace_03.py
@@ -1,2 +1,2 @@
from xhpy.pylib import *
-print <a> {'a'} </a>
+result = <a> {'a'} </a>
View
2  xhpy/tests/full/whitespace_04.py
@@ -1,2 +1,2 @@
from xhpy.pylib import *
-print <a> <a /> {'a'} </a>
+result = <a> <a /> {'a'} </a>
View
2  xhpy/tests/full/whitespace_05.py
@@ -1,5 +1,5 @@
from xhpy.pylib import *
-print\
+result = \
<a>
foo
</a>
View
2  xhpy/tests/full/whitespace_06.py
@@ -1,2 +1,2 @@
from xhpy.pylib import *
-print <a> a { 'b' } c </a>
+result = <a> a { 'b' } c </a>
View
2  xhpy/tests/full/whitespace_07.py
@@ -1,2 +1,2 @@
from xhpy.pylib import *
-print <a> a{ 'b' }c </a>
+result = <a> a{ 'b' }c </a>
View
2  xhpy/tests/full/xhpy_function_param.py
@@ -6,4 +6,4 @@ def __init__(self, _1={}, _2=[]):
def exist(self):
pass
id(<thing />).exist()
-print 'pass'
+result = 'pass'
View
4 xhpy/tests/precompiled/cleanup_tests
@@ -0,0 +1,4 @@
+#!/bin/bash
+
+cd $(dirname $0)
+rm -rv xhpy_precompiled
View
1  xhpy/tests/precompiled/run_tests
@@ -5,3 +5,4 @@ $MYDIR/setup_tests
for FILE in $MYDIR/*.py; do
python "$FILE"
done
+#$MYDIR/cleanup_tests
View
8 xhpy/tests/precompiled/setup_tests
@@ -1,13 +1,15 @@
#!/bin/bash
cd $(dirname $0)
-mkdir -p pylib
+mkdir -p xhpy_precompiled
+mkdir -p xhpy_precompiled/pylib
# Copy over dependent files, etc.
-cp ../../pylib/*.py pylib
+cp ../../*.py xhpy_precompiled
+cp ../../pylib/*.py xhpy_precompiled/pylib
# Generate the core libraries, move back over source files.
-for FILE in pylib/*.py; do
+for FILE in xhpy_precompiled/pylib/*.py; do
echo "generating core library: $FILE..."
python ../../parser.py < "$FILE" > "${FILE%%.py}.xhpy"
mv "${FILE%%.py}.xhpy" "$FILE"
View
4 xhpy/tests/precompiled/tests/test.py.in
@@ -1,5 +1,5 @@
-from pylib.core import *
-from pylib.html import *
+from xhpy_precompiled.pylib.core import *
+from xhpy_precompiled.pylib.html import *
class :ui:foo(:x:element):
attribute list bar
Please sign in to comment.
Something went wrong with that request. Please try again.