From 39cd81d663d18cdd707dc2dca9fc2ab1ebe024de Mon Sep 17 00:00:00 2001 From: Shlomi Fish Date: Sun, 15 Apr 2018 17:37:49 +0300 Subject: [PATCH] Refactor/optimize: get rid of TAP.Simple. It was underused and unneeded. --- scripts/gen_individual_importing_tests.py | 7 +- tests/lib/TAP/Simple.py | 43 -------- tests/lib/TAP/__init__.py | 117 ---------------------- 3 files changed, 2 insertions(+), 165 deletions(-) delete mode 100644 tests/lib/TAP/Simple.py delete mode 100644 tests/lib/TAP/__init__.py diff --git a/scripts/gen_individual_importing_tests.py b/scripts/gen_individual_importing_tests.py index 997b6a19..9699781e 100644 --- a/scripts/gen_individual_importing_tests.py +++ b/scripts/gen_individual_importing_tests.py @@ -202,11 +202,8 @@ for module_name in \ if ver == 2 or "gtk" not in module_name: open(os.path.join(".", "tests", "individually-importing", "import_v" + str(ver) + "_" + module_name + ".py"), 'w').write('''#!/usr/bin/env python%(ver)d import sys -sys.path.append("./tests/lib") -from TAP.Simple import plan, ok - -plan(1) +print('1..1') sys.path.insert(0, ".") import %(module_name)s -ok(1, "imported") +print('ok 1 - imported') ''' % {'module_name': module_name, 'ver': ver}) diff --git a/tests/lib/TAP/Simple.py b/tests/lib/TAP/Simple.py deleted file mode 100644 index 00c0a5d9..00000000 --- a/tests/lib/TAP/Simple.py +++ /dev/null @@ -1,43 +0,0 @@ - -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 diff --git a/tests/lib/TAP/__init__.py b/tests/lib/TAP/__init__.py deleted file mode 100644 index 741a5e26..00000000 --- a/tests/lib/TAP/__init__.py +++ /dev/null @@ -1,117 +0,0 @@ -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 is None: - True - 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.keys(): - 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