<s> """<STR_LIT>""" <EOL> __author__ = '<STR_LIT>' <EOL> import unittest <EOL> import benchmark <EOL> import mocks <EOL> class BenchmarkTest ( unittest . TestCase ) : <EOL> def testCreateTestsWeighted ( self ) : <EOL> b = benchmark . Benchmark ( [ mocks . MockNameServer ( mocks . GOOD_IP ) ] , <EOL> test_count = <NUM_LIT:1000> ) <EOL> results = b . CreateTests ( ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> self . assertEquals ( len ( results ) , <NUM_LIT:1000> ) <EOL> self . assertTrue ( ( '<STR_LIT:A>' , '<STR_LIT>' ) in results ) <EOL> caches = [ x for x in results if '<STR_LIT>' in x [ <NUM_LIT:1> ] ] <EOL> self . assertTrue ( len ( caches ) > <NUM_LIT:0> and len ( caches ) < <NUM_LIT:50> ) <EOL> def testCreateTestsSingle ( self ) : <EOL> b = benchmark . Benchmark ( [ mocks . MockNameServer ( mocks . GOOD_IP ) ] , <EOL> test_count = <NUM_LIT:1> ) <EOL> results = b . CreateTests ( ( '<STR_LIT>' , ) ) <EOL> self . assertEquals ( results , [ [ '<STR_LIT:A>' , '<STR_LIT>' ] ] ) <EOL> self . assertRaises ( AssertionError , b . CreateTests , '<STR_LIT>' ) <EOL> def testCreateTestsChunkRecords ( self ) : <EOL> b = benchmark . Benchmark ( [ mocks . MockNameServer ( mocks . GOOD_IP ) ] , <EOL> test_count = <NUM_LIT:100> ) <EOL> results = b . CreateTests ( ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> select_mode = '<STR_LIT>' ) <EOL> self . assertEquals ( results , [ [ '<STR_LIT:A>' , '<STR_LIT>' ] , <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] ] ) <EOL> def testEmptyRun ( self ) : <EOL> ns_list = ( mocks . MockNameServer ( mocks . GOOD_IP ) , ) <EOL> b = benchmark . Benchmark ( ns_list , test_count = <NUM_LIT:3> , run_count = <NUM_LIT:2> ) <EOL> self . assertRaises ( AssertionError , b . Run ) <EOL> def testRun ( self ) : <EOL> ns_list = ( mocks . MockNameServer ( mocks . GOOD_IP ) , <EOL> mocks . MockNameServer ( mocks . PERFECT_IP ) , <EOL> mocks . MockNameServer ( mocks . BROKEN_IP ) , <EOL> mocks . MockNameServer ( mocks . SLOW_IP ) ) <EOL> b = benchmark . Benchmark ( ns_list , test_count = <NUM_LIT:3> , run_count = <NUM_LIT:2> ) <EOL> self . assertRaises ( AssertionError , b . Run ) <EOL> b . CreateTests ( [ '<STR_LIT>' ] ) <EOL> self . assertEquals ( b . test_data , [ [ '<STR_LIT:A>' , '<STR_LIT>' ] , <EOL> [ '<STR_LIT:A>' , '<STR_LIT>' ] , <EOL> [ '<STR_LIT:A>' , '<STR_LIT>' ] ] ) <EOL> b . Run ( ) <EOL> ips_tested = sorted ( [ x . ip for x in b . results ] ) <EOL> expected = [ '<STR_LIT:127.0.0.1>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> self . assertEquals ( ips_tested , expected ) <EOL> self . assertEquals ( len ( b . results [ ns_list [ <NUM_LIT:0> ] ] ) , <NUM_LIT:2> ) <EOL> self . assertEquals ( len ( b . results [ ns_list [ <NUM_LIT:0> ] ] [ <NUM_LIT:0> ] ) , <NUM_LIT:3> ) <EOL> def testNormalRun ( self ) : <EOL> ns_list = ( mocks . MockNameServer ( mocks . GOOD_IP ) , <EOL> mocks . MockNameServer ( mocks . PERFECT_IP ) , <EOL> mocks . MockNameServer ( mocks . BROKEN_IP ) , <EOL> mocks . MockNameServer ( mocks . SLOW_IP ) ) <EOL> b = benchmark . Benchmark ( ns_list , test_count = <NUM_LIT:3> , run_count = <NUM_LIT:2> ) <EOL> b . CreateTests ( [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> b . Run ( ) <EOL> expected = [ '<STR_LIT:127.0.0.1>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> averages = dict ( [ ( x [ <NUM_LIT:0> ] . ip , x [ <NUM_LIT:1> ] ) for x in b . ComputeAverages ( ) ] ) <EOL> self . assertEquals ( len ( averages ) , <NUM_LIT:4> ) <EOL> self . assertTrue ( averages [ mocks . GOOD_IP ] >= <NUM_LIT:8> ) <EOL> self . assertTrue ( averages [ mocks . PERFECT_IP ] <= <NUM_LIT:5> ) <EOL> self . assertTrue ( averages [ mocks . BROKEN_IP ] >= <NUM_LIT> ) <EOL> self . assertTrue ( averages [ mocks . SLOW_IP ] >= <NUM_LIT:20> ) <EOL> self . assertEquals ( b . BestOverallNameServer ( ) , ns_list [ <NUM_LIT:1> ] ) <EOL> self . assertEquals ( b . NearestNameServers ( count = <NUM_LIT:2> ) , [ ns_list [ <NUM_LIT:1> ] , ns_list [ <NUM_LIT:0> ] ] ) <EOL> def testDigestion ( self ) : <EOL> ns_list = ( mocks . MockNameServer ( mocks . GOOD_IP ) , <EOL> mocks . MockNameServer ( mocks . PERFECT_IP ) , <EOL> mocks . MockNameServer ( mocks . BROKEN_IP ) , <EOL> mocks . MockNameServer ( mocks . SLOW_IP ) ) <EOL> b = benchmark . Benchmark ( ns_list ) <EOL> good = ns_list [ <NUM_LIT:0> ] . FakeAnswer ( None ) <EOL> bad = ns_list [ <NUM_LIT:0> ] . FakeAnswer ( None , no_answer = True ) <EOL> b . results = { <EOL> ns_list [ <NUM_LIT:0> ] : [ [ ( '<STR_LIT>' , '<STR_LIT:A>' , <NUM_LIT> , bad ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:A>' , <NUM_LIT> , good ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:A>' , <NUM_LIT> , good ) ] , <EOL> [ ( '<STR_LIT>' , '<STR_LIT:A>' , <NUM_LIT> , bad ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:A>' , <NUM_LIT> , good ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:A>' , <NUM_LIT> , good ) ] ] , <EOL> ns_list [ <NUM_LIT:1> ] : [ [ ( '<STR_LIT>' , '<STR_LIT:A>' , <NUM_LIT> , good ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:A>' , <NUM_LIT> , good ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:A>' , <NUM_LIT> , good ) ] , <EOL> [ ( '<STR_LIT>' , '<STR_LIT:A>' , <NUM_LIT> , good ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:A>' , <NUM_LIT> , good ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:A>' , <NUM_LIT> , good ) ] ] , <EOL> ns_list [ <NUM_LIT:2> ] : [ [ ( '<STR_LIT>' , '<STR_LIT:A>' , <NUM_LIT> , None ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:A>' , <NUM_LIT> , None ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:A>' , <NUM_LIT> , None ) ] , <EOL> [ ( '<STR_LIT>' , '<STR_LIT:A>' , <NUM_LIT> , None ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:A>' , <NUM_LIT> , None ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:A>' , <NUM_LIT> , None ) ] ] , <EOL> ns_list [ <NUM_LIT:3> ] : [ [ ( '<STR_LIT>' , '<STR_LIT:A>' , <NUM_LIT> , good ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:A>' , <NUM_LIT> , good ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:A>' , <NUM_LIT> , good ) ] , <EOL> [ ( '<STR_LIT>' , '<STR_LIT:A>' , <NUM_LIT> , good ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:A>' , <NUM_LIT> , bad ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:A>' , <NUM_LIT> , good ) ] ] } <EOL> expected = [ ] <EOL> averages = dict ( [ ( x [ <NUM_LIT:0> ] . ip , x [ <NUM_LIT:1> ] ) for x in b . ComputeAverages ( ) ] ) <EOL> self . assertEquals ( averages [ mocks . GOOD_IP ] , <NUM_LIT> ) <EOL> self . assertEquals ( averages [ mocks . PERFECT_IP ] , <NUM_LIT> ) <EOL> self . assertEquals ( averages [ mocks . BROKEN_IP ] , <NUM_LIT> ) <EOL> self . assertEquals ( averages [ mocks . SLOW_IP ] , <NUM_LIT> ) <EOL> expected = [ ( '<STR_LIT>' , <NUM_LIT> ) , <EOL> ( '<STR_LIT:127.0.0.1>' , <NUM_LIT> ) , <EOL> ( '<STR_LIT>' , <NUM_LIT> ) , <EOL> ( '<STR_LIT>' , <NUM_LIT> ) ] <EOL> fastest = [ ( x [ <NUM_LIT:0> ] . ip , x [ <NUM_LIT:1> ] ) for x in b . FastestNameServerResult ( ) ] <EOL> self . assertEquals ( fastest , expected ) <EOL> expected = [ <EOL> ( None , '<STR_LIT>' , <NUM_LIT> ) , <EOL> ( None , '<STR_LIT>' , <NUM_LIT> ) , <EOL> ( None , '<STR_LIT>' , <NUM_LIT> ) , <EOL> ( None , '<STR_LIT>' , <EOL> <NUM_LIT> ) <EOL> ] <EOL> self . assertEquals ( b . _LowestLatencyAsciiChart ( ) , expected ) <EOL> def testFastest ( self ) : <EOL> ns_list = ( mocks . MockNameServer ( '<STR_LIT:X>' , name = '<STR_LIT:X>' ) , <EOL> mocks . MockNameServer ( '<STR_LIT:O>' , name = '<STR_LIT:O>' ) , <EOL> mocks . MockNameServer ( '<STR_LIT>' , name = '<STR_LIT>' ) ) <EOL> b = benchmark . Benchmark ( ns_list ) <EOL> good = ns_list [ <NUM_LIT:0> ] . FakeAnswer ( None ) <EOL> b . results = { <EOL> ns_list [ <NUM_LIT:0> ] : [ [ ( '<STR_LIT>' , '<STR_LIT:A>' , <NUM_LIT> , good ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:A>' , <NUM_LIT> , good ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:A>' , <NUM_LIT> , good ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:A>' , <NUM_LIT> , good ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:A>' , <NUM_LIT> , good ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:A>' , <NUM_LIT> , good ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:A>' , <NUM_LIT> , good ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:A>' , <NUM_LIT> , good ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:A>' , <NUM_LIT> , good ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:A>' , <NUM_LIT> , good ) ] ] , <EOL> ns_list [ <NUM_LIT:1> ] : [ [ ( '<STR_LIT>' , '<STR_LIT:A>' , <NUM_LIT> , good ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:A>' , <NUM_LIT> , good ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:A>' , <NUM_LIT> , good ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:A>' , <NUM_LIT> , good ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:A>' , <NUM_LIT> , good ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:A>' , <NUM_LIT> , good ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:A>' , <NUM_LIT> , good ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:A>' , <NUM_LIT> , good ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:A>' , <NUM_LIT> , good ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:A>' , <NUM_LIT> , good ) ] ] , <EOL> ns_list [ <NUM_LIT:2> ] : [ [ ( '<STR_LIT>' , '<STR_LIT:A>' , <NUM_LIT> , good ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:A>' , <NUM_LIT> , good ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:A>' , <NUM_LIT> , good ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:A>' , <NUM_LIT> , good ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:A>' , <NUM_LIT> , good ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:A>' , <NUM_LIT> , good ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:A>' , <NUM_LIT> , good ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:A>' , <NUM_LIT> , good ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:A>' , <NUM_LIT> , good ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:A>' , <NUM_LIT> , good ) ] ] <EOL> } <EOL> expected = [ ( '<STR_LIT>' , <NUM_LIT> ) , <EOL> ( '<STR_LIT>' , <NUM_LIT> ) , <EOL> ( '<STR_LIT:O>' , <NUM_LIT> ) ] <EOL> fastest = [ ( x [ <NUM_LIT:0> ] . ip , x [ <NUM_LIT:1> ] ) for x in b . FastestNameServerResult ( ) ] <EOL> self . assertEquals ( fastest , expected ) <EOL> expected = [ <EOL> ( '<STR_LIT:X>' , '<STR_LIT>' , <NUM_LIT> ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' , <NUM_LIT> ) , <EOL> ( '<STR_LIT:O>' , '<STR_LIT>' , <EOL> <NUM_LIT> ) <EOL> ] <EOL> self . assertEquals ( b . _LowestLatencyAsciiChart ( ) , expected ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
