<s> import collections <EOL> import time <EOL> import unittest <EOL> import threading <EOL> from unittest . mock import patch <EOL> from fbtftp . base_server import ServerStats <EOL> class testServerStats ( unittest . TestCase ) : <EOL> @ patch ( '<STR_LIT>' ) <EOL> def setUp ( self , mock ) : <EOL> self . st = ServerStats ( server_addr = "<STR_LIT:127.0.0.1>" , interval = <NUM_LIT:2> ) <EOL> self . start_time = time . time ( ) <EOL> self . assertEqual ( self . st . server_addr , "<STR_LIT:127.0.0.1>" ) <EOL> self . assertEqual ( self . st . interval , <NUM_LIT:2> ) <EOL> self . assertLessEqual ( self . st . start_time , self . start_time ) <EOL> self . assertIsInstance ( self . st . _counters , collections . Counter ) <EOL> self . assertIsInstance ( self . st . _counters_lock , type ( threading . Lock ( ) ) ) <EOL> self . st . _counters_lock = mock ( ) <EOL> def testSetGetCounters ( self ) : <EOL> self . st . set_counter ( '<STR_LIT>' , <NUM_LIT:100> ) <EOL> self . assertEqual ( self . st . get_counter ( '<STR_LIT>' ) , <NUM_LIT:100> ) <EOL> self . assertEqual ( self . st . _counters_lock . __enter__ . call_count , <NUM_LIT:1> ) <EOL> self . assertEqual ( self . st . _counters_lock . __exit__ . call_count , <NUM_LIT:1> ) <EOL> def testIncrementCounter ( self ) : <EOL> self . st . set_counter ( '<STR_LIT>' , <NUM_LIT:100> ) <EOL> self . st . increment_counter ( '<STR_LIT>' ) <EOL> self . assertEqual ( self . st . get_counter ( '<STR_LIT>' ) , <NUM_LIT> ) <EOL> self . assertEqual ( self . st . _counters_lock . __enter__ . call_count , <NUM_LIT:2> ) <EOL> self . assertEqual ( self . st . _counters_lock . __exit__ . call_count , <NUM_LIT:2> ) <EOL> def testResetCounter ( self ) : <EOL> self . st . set_counter ( '<STR_LIT>' , <NUM_LIT:100> ) <EOL> self . assertEqual ( self . st . get_counter ( '<STR_LIT>' ) , <NUM_LIT:100> ) <EOL> self . st . reset_counter ( '<STR_LIT>' ) <EOL> self . assertEqual ( self . st . get_counter ( '<STR_LIT>' ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( self . st . _counters_lock . __enter__ . call_count , <NUM_LIT:2> ) <EOL> self . assertEqual ( self . st . _counters_lock . __exit__ . call_count , <NUM_LIT:2> ) <EOL> def testGetAndResetCounter ( self ) : <EOL> self . st . set_counter ( '<STR_LIT>' , <NUM_LIT:100> ) <EOL> self . assertEqual ( self . st . get_and_reset_counter ( '<STR_LIT>' ) , <NUM_LIT:100> ) <EOL> self . assertEqual ( self . st . get_counter ( '<STR_LIT>' ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( self . st . _counters_lock . __enter__ . call_count , <NUM_LIT:2> ) <EOL> self . assertEqual ( self . st . _counters_lock . __exit__ . call_count , <NUM_LIT:2> ) <EOL> def testGetAllCounters ( self ) : <EOL> self . st . set_counter ( '<STR_LIT>' , <NUM_LIT:100> ) <EOL> self . st . set_counter ( '<STR_LIT>' , <NUM_LIT:200> ) <EOL> counters = self . st . get_all_counters ( ) <EOL> self . assertEqual ( len ( counters ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( self . st . _counters_lock . __enter__ . call_count , <NUM_LIT:3> ) <EOL> self . assertEqual ( self . st . _counters_lock . __exit__ . call_count , <NUM_LIT:3> ) <EOL> def testGetAndResetAllCounters ( self ) : <EOL> self . st . set_counter ( '<STR_LIT>' , <NUM_LIT:100> ) <EOL> self . st . set_counter ( '<STR_LIT>' , <NUM_LIT:200> ) <EOL> counters = self . st . get_and_reset_all_counters ( ) <EOL> self . assertEqual ( len ( counters ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( counters [ '<STR_LIT>' ] , <NUM_LIT:100> ) <EOL> self . assertEqual ( counters [ '<STR_LIT>' ] , <NUM_LIT:200> ) <EOL> self . assertEqual ( self . st . _counters_lock . __enter__ . call_count , <NUM_LIT:3> ) <EOL> self . assertEqual ( self . st . _counters_lock . __exit__ . call_count , <NUM_LIT:3> ) <EOL> def testResetAllCounters ( self ) : <EOL> self . st . set_counter ( '<STR_LIT>' , <NUM_LIT:100> ) <EOL> self . st . set_counter ( '<STR_LIT>' , <NUM_LIT:200> ) <EOL> self . st . reset_all_counters ( ) <EOL> self . assertEqual ( self . st . get_counter ( '<STR_LIT>' ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( self . st . get_counter ( '<STR_LIT>' ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( self . st . _counters_lock . __enter__ . call_count , <NUM_LIT:3> ) <EOL> self . assertEqual ( self . st . _counters_lock . __exit__ . call_count , <NUM_LIT:3> ) <EOL> def testDuration ( self ) : <EOL> self . assertGreater ( self . st . duration ( ) , <NUM_LIT:0> ) </s>
