#!/usr/bin/env python3

##  Copyright (c) 2011 Steven D'Aprano.
##  See the file stats/__init__.py for the licence terms for this software.

"""
Run the test suite for the stats package.

"""

import unittest


# Tests to run:
import stats._tests.basic
import stats._tests.co
import stats._tests.general
import stats._tests.multivar
import stats._tests.order
import stats._tests.univar
import stats._tests.utils


if __name__ == '__main__' and __package__ is not None:
    modules = (
        stats._tests.basic,
        stats._tests.co,
        stats._tests.general,
        stats._tests.multivar,
        stats._tests.order,
        stats._tests.univar,
        stats._tests.utils,
        )
    total = failures = errors = skipped = 0
    for module in modules:
        print("\n+++ Testing module %s +++" % module.__name__)
        x = unittest.main(exit=False, module=module).result
        total += x.testsRun
        failures += len(x.failures)
        errors += len(x.errors)
        skipped += len(x.skipped)
        #suite = unittest.TestLoader().loadTestsFromTestCase(TestSequenceFunctions)
        #unittest.TextTestRunner(verbosity=2).run(suite)
        #unittest.TextTestRunner(verbosity=0).run(doc_test_suite)
    print("\n" + "*"*70 + "\n")
    print("+++ Summary +++\n")
    print("Ran %d tests in %d modules: %d failures, %d errors, %d skipped.\n"
          % (total, len(modules), failures, errors, skipped))


@@ -190,26 +190,952 @@
 %22%22%0A%0A
-import unittest%0A%0A%0A
+#import doctests%0Aimport gc%0Aimport os%0Aimport sys%0Aimport time%0Aimport unittest%0A%0A%0Adef setup():%0A    gc.collect()%0A    assert not gc.garbage%0A%0A%0Adef run_doctests():  # FIXME%0A    print(%22WARNING: skipping doctests.%22)%0A    return%0A    failures, tests = doctest.testmod(stats)%0A    if failures:%0A        print(%22Skipping further tests while doctests failing.%22)%0A        sys.exit(1)%0A    else:%0A        print(%22Doctests: failed %25d, attempted %25d%22 %25 (failures, tests))%0A%0A%0Adef run_example_tests():%0A    if os.path.exists('examples.txt'):%0A        failures, tests = doctest.testfile('examples.txt')%0A        if failures:%0A            print(%22Skipping further tests while example doctests failing.%22)%0A            sys.exit(1)%0A        else:%0A            print(%22Example doc tests: failed %25d, attempted %25d%22 %25 (failures, tests))%0A    else:%0A        print('WARNING: No example text file found.')%0A%0A%0Adef run_unittests():%0A    t0 = time.time()%0A    total = failures = errors = skipped = 0%0A    
 # Te
@@ -1146,16 +1146,20 @@
 to run:%0A
+    
 import s
@@ -1176,16 +1176,20 @@
 s.basic%0A
+    
 import s
@@ -1203,16 +1203,20 @@
 ests.co%0A
+    
 import s
@@ -1235,16 +1235,20 @@
 general%0A
+    
 import s
@@ -1264,24 +1264,28 @@
 ts.multivar%0A
+    
 import stats
@@ -1298,16 +1298,20 @@
 s.order%0A
+    
 import s
@@ -1329,16 +1329,20 @@
 .univar%0A
+    
 import s
@@ -1363,65 +1363,8 @@
 ils%0A
-%0A%0Aif __name__ == '__main__' and __package__ is not None:%0A
     
@@ -1588,52 +1588,8 @@
   )%0A
-    total = failures = errors = skipped = 0%0A
     
@@ -2067,24 +2067,49 @@
 test_suite)%0A
+    t = time.time() - t0%0A
     print(%22%5C
@@ -2200,108 +2200,760 @@
 ules
-: %25d failures, %25d errors, %25d skipped.%5Cn%22%0A          %25 (total, len(modules), failures, errors, skipped)
+ in %25.3f seconds:%22%0A          %25 (total, len(modules), t))%0A    print(%22%25d failures, %25d errors, %25d skipped.%5Cn%22%0A          %25 (failures, errors, skipped))%0A    return modules%0A%0A%0Adef run_garbage_detector(make_garbage=False):%0A    # Simple garbage detector.%0A    if make_garbage:%0A        # Force a cycle that will be detected.%0A        class Junk:%0A            def __del__(self):%0A                pass%0A        t = Junk()%0A        t.rubbish = t%0A        del t%0A    gc.collect()%0A    if gc.garbage:%0A        print(%22List of uncollectable garbage:%22)%0A        print(gc.garbage)%0A    else:%0A        print(%22No garbage found.%22)%0A%0A%0Aif __name__ == '__main__' and __package__ is not None:%0A    setup()%0A    run_doctests()%0A    run_example_tests()%0A    run_unittests()%0A    run_garbage_detector(
 )%0A%0A

Test for uncollectable garbage, refactor top-level test interface.