Test flexibility

This commit is contained in:
jtm
2012-02-12 12:37:54 +00:00
parent 7a3ff7cf7e
commit b849fafe26
6 changed files with 40 additions and 16 deletions

View File

@@ -5,20 +5,14 @@ import unittest
import sys, os
import re
here = os.path.dirname(__file__)
path = os.path.abspath(here)
while os.path.dirname(path) != path:
if os.path.exists(os.path.join(path, 'lesscpy', '__init__.py')):
sys.path.insert(0, path)
break
path = os.path.dirname(path)
import bootstrap
def find():
svn = re.compile('\.svn')
test = re.compile('test.+\.py$')
skip = re.compile('testissues.*')
alltests = unittest.TestSuite()
for path, dirs, files in os.walk(here):
for path, dirs, files in os.walk(bootstrap.here):
if svn.search(path):
continue
for f in files:
@@ -30,4 +24,5 @@ def find():
return alltests
if __name__ == '__main__':
unittest.main(defaultTest='find')
unittest.main(defaultTest='find')

13
lesscpy/test/bootstrap.py Normal file
View File

@@ -0,0 +1,13 @@
"""
Test bootstrap module. For flexible testing.
"""
import os
import sys
here = os.path.dirname(__file__)
path = os.path.abspath(here)
while os.path.dirname(path) != path:
if os.path.exists(os.path.join(path, 'lesscpy', '__init__.py')):
sys.path.insert(0, path)
break
path = os.path.dirname(path)

View File

@@ -2,6 +2,8 @@
lesscpy tests.
"""
import unittest
if __name__ == '__main__':
import bootstrap
from lesscpy.lessc import color

View File

@@ -1,4 +1,6 @@
import unittest
if __name__ == '__main__':
import bootstrap
from lesscpy.plib.expression import Expression
from mockp import Mockp

View File

@@ -1,16 +1,21 @@
import unittest
if __name__ == '__main__':
import bootstrap
from lesscpy.plib.process import Process
from lesscpy.plib.variable import Variable
from lesscpy.lessc.scope import Scope
from mockp import Mockp
class TestProcess(unittest.TestCase):
def testswap(self):
p = Process(Mockp([]))
p.scope = [{}]
p.scope = Scope()
p.scope.push()
self.assertRaises(SyntaxError, p.swap, '@var')
p.scope = [{'@var': Variable(Mockp(['@var', ':', ['1']]))}]
p.scope.add_variable(Variable(Mockp(['@var', ':', ['1']])))
self.assertEqual('1', p.swap('@var'))
p.scope.append({'@var': Variable(Mockp(['@var', ':', ['2']]))})
p.scope.push()
p.scope.add_variable(Variable(Mockp(['@var', ':', ['2']])))
self.assertEqual('2', p.swap('@var'))
p.scope.pop()
self.assertEqual('1', p.swap('@var'))
@@ -20,8 +25,10 @@ class TestProcess(unittest.TestCase):
def testswapvarvar(self):
p = Process(Mockp([]))
p.scope = [{'@var': Variable(Mockp(['@var', ':', ['1']]))}]
p.scope.append({'@name': Variable(Mockp(['@name', ':', ['var']]))})
p.scope = Scope()
p.scope.push()
p.scope.add_variable(Variable(Mockp(['@var', ':', ['1']])))
p.scope.add_variable(Variable(Mockp(['@name', ':', ['var']])))
self.assertEqual('1', p.swap('@@name'))
self.assertEqual('1 ', p.swap('@@name '))
self.assertEqual('-1', p.swap('-@@name'))
@@ -29,8 +36,11 @@ class TestProcess(unittest.TestCase):
def testreplace(self):
p = Process(Mockp([]))
p.scope = [{'@var': Variable(Mockp(['@var', ':', ['1']]))}]
p.scope.append({'@var2': Variable(Mockp(['@var2', ':', ['2']]))})
p.scope = Scope()
p.scope.push()
p.scope.add_variable(Variable(Mockp(['@var', ':', ['1']])))
p.scope.push()
p.scope.add_variable(Variable(Mockp(['@var2', ':', ['2']])))
t = p.replace_vars(['1', '@var2', 'm', '@var'])
self.assertEqual(t, ['1', '2', 'm', '1'])
t = p.replace_vars(['1', '-@var2 ', 'm', '-@var'])

View File

@@ -1,5 +1,7 @@
import unittest
if __name__ == '__main__':
import bootstrap
import lesscpy.lessc.utility as utility
class TestUtility(unittest.TestCase):