mirror of
https://github.com/shlomif/PySolFC.git
synced 2025-04-05 00:02:29 -04:00
Add the first individually-importing test.
This commit is contained in:
parent
4ee830ae2f
commit
424c758815
4 changed files with 147 additions and 0 deletions
3
Makefile
3
Makefile
|
@ -58,3 +58,6 @@ mo:
|
|||
done
|
||||
cp -f locale/pl/LC_MESSAGES/pysol.mo locale/pl_PL/LC_MESSAGES/pysol.mo
|
||||
cp -f locale/it/LC_MESSAGES/pysol.mo locale/it_IT/LC_MESSAGES/pysol.mo
|
||||
|
||||
test:
|
||||
runprove tests/individually-importing/*.py
|
||||
|
|
9
tests/individually-importing/import_mfxutils.py
Normal file
9
tests/individually-importing/import_mfxutils.py
Normal file
|
@ -0,0 +1,9 @@
|
|||
#!/usr/bin/env python
|
||||
import sys
|
||||
sys.path.append("./tests/lib")
|
||||
from TAP.Simple import plan, ok
|
||||
|
||||
plan(1)
|
||||
sys.path.append(".")
|
||||
import pysollib.mfxutil
|
||||
ok(1, "imported")
|
37
tests/lib/TAP/Simple.py
Normal file
37
tests/lib/TAP/Simple.py
Normal file
|
@ -0,0 +1,37 @@
|
|||
|
||||
import TAP
|
||||
import re
|
||||
|
||||
builder = TAP.Builder()
|
||||
|
||||
def plan(plan, plan_param=None):
|
||||
builder.set_plan(plan, plan_param)
|
||||
|
||||
ok = builder.ok
|
||||
|
||||
def diag(comment):
|
||||
print "# %s" % re.compile("\n(.)").sub(comment, '\n#\1')
|
||||
|
||||
def eq_ok(have, want, comment):
|
||||
okness = have == want
|
||||
ok(okness, comment)
|
||||
if not okness:
|
||||
diag("want: %s" % want)
|
||||
diag("have: %s" % have)
|
||||
return okness
|
||||
|
||||
def is_ok(have, want, comment):
|
||||
okness = have is want
|
||||
ok(okness, comment)
|
||||
if not okness:
|
||||
diag("want id: %s" % id(want))
|
||||
diag("have id: %s" % id(have))
|
||||
return okness
|
||||
|
||||
def isa_ok(object, cls, object_name="the object"):
|
||||
okness = isinstance(object, cls)
|
||||
ok(okness, object_name + " is a " + repr(cls))
|
||||
# if not okness:
|
||||
# diag("want id: %s" % id(want))
|
||||
# diag("have id: %s" % id(have))
|
||||
return okness
|
98
tests/lib/TAP/__init__.py
Normal file
98
tests/lib/TAP/__init__.py
Normal file
|
@ -0,0 +1,98 @@
|
|||
import sys
|
||||
import atexit
|
||||
|
||||
# todo: make written-to stream passable
|
||||
|
||||
class Plan(object):
|
||||
def __init__(self, plan, param=None):
|
||||
self.counter = 0
|
||||
self.expected_tests = None
|
||||
self.ended = False
|
||||
|
||||
if isinstance(plan, int):
|
||||
self.expected_tests = plan
|
||||
print "1..%u" % self.expected_tests
|
||||
elif plan == "no_plan" or plan == None: 1
|
||||
elif plan == "skip_all":
|
||||
print "1..0 # skip %s" % param
|
||||
raise SystemExit(0) # ??? this is what T::B does, but sucks
|
||||
else:
|
||||
raise TestBadPlan(plan)
|
||||
|
||||
def increment_counter(self):
|
||||
self.counter += 1
|
||||
|
||||
def __del__(self):
|
||||
if self.ended: return
|
||||
self.ended = True
|
||||
if self.expected_tests is None:
|
||||
print "1..%u" % self.counter
|
||||
elif self.counter != self.expected_tests:
|
||||
print "# Looks like you planned %u tests but ran %u." \
|
||||
% (self.expected_tests, self.counter)
|
||||
|
||||
class Builder(object):
|
||||
global_defaults = {
|
||||
"_plan": None,
|
||||
"current": 1,
|
||||
"has_plan": False,
|
||||
}
|
||||
global_test_builder = global_defaults.copy()
|
||||
|
||||
def __init__(self, plan=None, plan_param=None):
|
||||
self.__dict__ = self.global_test_builder
|
||||
if plan: self.set_plan(plan, plan_param)
|
||||
|
||||
@classmethod # XXX: why did this fail?
|
||||
def create(cls, plan=None, plan_param=None):
|
||||
# self = new.instance(cls) # ? this sucks, too
|
||||
self = Builder()
|
||||
self.__dict__ = self.global_defaults.copy()
|
||||
if plan: self.set_plan(plan, plan_param)
|
||||
return self
|
||||
|
||||
def set_plan(self, plan, plan_param=None):
|
||||
if self.get_plan(): raise TestPlannedAlready(plan, plan_param)
|
||||
self._plan = Plan(plan, plan_param)
|
||||
atexit.register(self._plan.__del__)
|
||||
|
||||
def get_plan(self): return self._plan
|
||||
|
||||
def ok(self, is_ok, desc=None, skip=None, todo=None):
|
||||
self.get_plan().increment_counter()
|
||||
if is_ok: report = "ok"
|
||||
else: report = "not ok"
|
||||
|
||||
sys.stdout.write("%s %u" % (report, self.current))
|
||||
|
||||
if desc: sys.stdout.write(" - %s" % desc)
|
||||
if skip: sys.stdout.write(" # SKIP %s" % skip)
|
||||
if todo: sys.stdout.write(" # TODO %s" % todo)
|
||||
|
||||
print
|
||||
|
||||
self.current += 1
|
||||
|
||||
return is_ok
|
||||
|
||||
def reset(self):
|
||||
self.__dict__.clear()
|
||||
for key in self.global_defaults.iterkeys():
|
||||
self.__dict__[key] = self.global_defaults[key]
|
||||
|
||||
class TestPlannedAlready(Exception):
|
||||
def __init__(self, plan, param=None):
|
||||
self.plan = plan
|
||||
self.param = param
|
||||
def __str__(self):
|
||||
return "tried to plan twice; second plan: %s, %s" % self.plan, self.param
|
||||
|
||||
class TestWithoutPlan(Exception):
|
||||
def __str__(self):
|
||||
return "tried running tests without a plan"
|
||||
|
||||
class TestBadPlan(Exception):
|
||||
def __init__(self, plan):
|
||||
self.plan = plan
|
||||
def __str__(self):
|
||||
return "didn't understand plan '%s'" % self.plan
|
Loading…
Add table
Reference in a new issue