<s> """<STR_LIT>""" <EOL> import sys <EOL> import time <EOL> from unittest import TestResult , TestSuite , defaultTestLoader <EOL> from . testsuite . hashindex import HashIndexDataTestCase , HashIndexRefcountingTestCase , HashIndexTestCase <EOL> from . testsuite . crypto import CryptoTestCase <EOL> from . testsuite . chunker import ChunkerTestCase <EOL> SELFTEST_CASES = [ <EOL> HashIndexDataTestCase , <EOL> HashIndexRefcountingTestCase , <EOL> HashIndexTestCase , <EOL> CryptoTestCase , <EOL> ChunkerTestCase , <EOL> ] <EOL> SELFTEST_COUNT = <NUM_LIT> <EOL> class SelfTestResult ( TestResult ) : <EOL> def __init__ ( self ) : <EOL> super ( ) . __init__ ( ) <EOL> self . successes = [ ] <EOL> def addSuccess ( self , test ) : <EOL> super ( ) . addSuccess ( test ) <EOL> self . successes . append ( test ) <EOL> def test_name ( self , test ) : <EOL> return test . shortDescription ( ) or str ( test ) <EOL> def log_results ( self , logger ) : <EOL> for test , failure in self . errors + self . failures + self . unexpectedSuccesses : <EOL> logger . error ( '<STR_LIT>' , self . test_name ( test ) , failure ) <EOL> for test , reason in self . skipped : <EOL> logger . warning ( '<STR_LIT>' , self . test_name ( test ) , reason ) <EOL> def successful_test_count ( self ) : <EOL> return len ( self . successes ) <EOL> def selftest ( logger ) : <EOL> selftest_started = time . perf_counter ( ) <EOL> result = SelfTestResult ( ) <EOL> test_suite = TestSuite ( ) <EOL> for test_case in SELFTEST_CASES : <EOL> test_suite . addTest ( defaultTestLoader . loadTestsFromTestCase ( test_case ) ) <EOL> test_suite . run ( result ) <EOL> result . log_results ( logger ) <EOL> successful_tests = result . successful_test_count ( ) <EOL> count_mismatch = successful_tests != SELFTEST_COUNT <EOL> if result . wasSuccessful ( ) and count_mismatch : <EOL> logger . error ( "<STR_LIT>" <EOL> "<STR_LIT>" , <EOL> successful_tests , SELFTEST_COUNT ) <EOL> if not result . wasSuccessful ( ) or count_mismatch : <EOL> logger . error ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> sys . exit ( <NUM_LIT:2> ) <EOL> assert False , "<STR_LIT>" <EOL> selftest_elapsed = time . perf_counter ( ) - selftest_started <EOL> logger . debug ( "<STR_LIT>" , successful_tests , selftest_elapsed ) </s>
