<s> """<STR_LIT>""" <EOL> import unittest <EOL> import mock <EOL> import psutil <EOL> class AlreadyListeningTest ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def _call ( self , * args , ** kwargs ) : <EOL> from certbot . plugins . util import already_listening <EOL> return already_listening ( * args , ** kwargs ) <EOL> @ mock . patch ( "<STR_LIT>" ) <EOL> @ mock . patch ( "<STR_LIT>" ) <EOL> @ mock . patch ( "<STR_LIT>" ) <EOL> def test_race_condition ( self , mock_get_utility , mock_process , mock_net ) : <EOL> from psutil . _common import sconn <EOL> conns = [ <EOL> sconn ( fd = - <NUM_LIT:1> , family = <NUM_LIT:2> , type = <NUM_LIT:1> , laddr = ( "<STR_LIT>" , <NUM_LIT:30> ) , <EOL> raddr = ( ) , status = "<STR_LIT>" , pid = None ) , <EOL> sconn ( fd = <NUM_LIT:3> , family = <NUM_LIT:2> , type = <NUM_LIT:1> , laddr = ( "<STR_LIT>" , <NUM_LIT> ) , <EOL> raddr = ( "<STR_LIT>" , <NUM_LIT> ) , status = "<STR_LIT>" , pid = <NUM_LIT> ) , <EOL> sconn ( fd = - <NUM_LIT:1> , family = <NUM_LIT:10> , type = <NUM_LIT:1> , laddr = ( "<STR_LIT>" , <NUM_LIT> ) , <EOL> raddr = ( "<STR_LIT>" , <NUM_LIT> ) , status = "<STR_LIT>" , pid = None ) , <EOL> sconn ( fd = <NUM_LIT:3> , family = <NUM_LIT:2> , type = <NUM_LIT:1> , laddr = ( "<STR_LIT>" , <NUM_LIT> ) , <EOL> raddr = ( ) , status = "<STR_LIT>" , pid = <NUM_LIT> ) ] <EOL> mock_net . return_value = conns <EOL> mock_process . side_effect = psutil . NoSuchProcess ( "<STR_LIT>" ) <EOL> self . assertFalse ( self . _call ( <NUM_LIT> ) ) <EOL> self . assertEqual ( mock_get_utility . generic_notification . call_count , <NUM_LIT:0> ) <EOL> mock_process . assert_called_once_with ( <NUM_LIT> ) <EOL> @ mock . patch ( "<STR_LIT>" ) <EOL> @ mock . patch ( "<STR_LIT>" ) <EOL> @ mock . patch ( "<STR_LIT>" ) <EOL> def test_not_listening ( self , mock_get_utility , mock_process , mock_net ) : <EOL> from psutil . _common import sconn <EOL> conns = [ <EOL> sconn ( fd = - <NUM_LIT:1> , family = <NUM_LIT:2> , type = <NUM_LIT:1> , laddr = ( "<STR_LIT>" , <NUM_LIT:30> ) , <EOL> raddr = ( ) , status = "<STR_LIT>" , pid = None ) , <EOL> sconn ( fd = <NUM_LIT:3> , family = <NUM_LIT:2> , type = <NUM_LIT:1> , laddr = ( "<STR_LIT>" , <NUM_LIT> ) , <EOL> raddr = ( "<STR_LIT>" , <NUM_LIT> ) , status = "<STR_LIT>" , pid = <NUM_LIT> ) , <EOL> sconn ( fd = - <NUM_LIT:1> , family = <NUM_LIT:10> , type = <NUM_LIT:1> , laddr = ( "<STR_LIT>" , <NUM_LIT> ) , <EOL> raddr = ( "<STR_LIT>" , <NUM_LIT> ) , status = "<STR_LIT>" , pid = None ) ] <EOL> mock_net . return_value = conns <EOL> mock_process . name . return_value = "<STR_LIT>" <EOL> self . assertFalse ( self . _call ( <NUM_LIT> ) ) <EOL> self . assertEqual ( mock_get_utility . generic_notification . call_count , <NUM_LIT:0> ) <EOL> self . assertEqual ( mock_process . call_count , <NUM_LIT:0> ) <EOL> @ mock . patch ( "<STR_LIT>" ) <EOL> @ mock . patch ( "<STR_LIT>" ) <EOL> @ mock . patch ( "<STR_LIT>" ) <EOL> def test_listening_ipv4 ( self , mock_get_utility , mock_process , mock_net ) : <EOL> from psutil . _common import sconn <EOL> conns = [ <EOL> sconn ( fd = - <NUM_LIT:1> , family = <NUM_LIT:2> , type = <NUM_LIT:1> , laddr = ( "<STR_LIT>" , <NUM_LIT:30> ) , <EOL> raddr = ( ) , status = "<STR_LIT>" , pid = None ) , <EOL> sconn ( fd = <NUM_LIT:3> , family = <NUM_LIT:2> , type = <NUM_LIT:1> , laddr = ( "<STR_LIT>" , <NUM_LIT> ) , <EOL> raddr = ( "<STR_LIT>" , <NUM_LIT> ) , status = "<STR_LIT>" , pid = <NUM_LIT> ) , <EOL> sconn ( fd = - <NUM_LIT:1> , family = <NUM_LIT:10> , type = <NUM_LIT:1> , laddr = ( "<STR_LIT>" , <NUM_LIT> ) , <EOL> raddr = ( "<STR_LIT>" , <NUM_LIT> ) , status = "<STR_LIT>" , pid = None ) , <EOL> sconn ( fd = <NUM_LIT:3> , family = <NUM_LIT:2> , type = <NUM_LIT:1> , laddr = ( "<STR_LIT>" , <NUM_LIT> ) , <EOL> raddr = ( ) , status = "<STR_LIT>" , pid = <NUM_LIT> ) ] <EOL> mock_net . return_value = conns <EOL> mock_process . name . return_value = "<STR_LIT>" <EOL> result = self . _call ( <NUM_LIT> ) <EOL> self . assertTrue ( result ) <EOL> self . assertEqual ( mock_get_utility . call_count , <NUM_LIT:1> ) <EOL> mock_process . assert_called_once_with ( <NUM_LIT> ) <EOL> @ mock . patch ( "<STR_LIT>" ) <EOL> @ mock . patch ( "<STR_LIT>" ) <EOL> @ mock . patch ( "<STR_LIT>" ) <EOL> def test_listening_ipv6 ( self , mock_get_utility , mock_process , mock_net ) : <EOL> from psutil . _common import sconn <EOL> conns = [ <EOL> sconn ( fd = - <NUM_LIT:1> , family = <NUM_LIT:2> , type = <NUM_LIT:1> , laddr = ( "<STR_LIT>" , <NUM_LIT:30> ) , <EOL> raddr = ( ) , status = "<STR_LIT>" , pid = None ) , <EOL> sconn ( fd = <NUM_LIT:3> , family = <NUM_LIT:2> , type = <NUM_LIT:1> , laddr = ( "<STR_LIT>" , <NUM_LIT> ) , <EOL> raddr = ( "<STR_LIT>" , <NUM_LIT> ) , status = "<STR_LIT>" , pid = <NUM_LIT> ) , <EOL> sconn ( fd = - <NUM_LIT:1> , family = <NUM_LIT:10> , type = <NUM_LIT:1> , laddr = ( "<STR_LIT>" , <NUM_LIT> ) , <EOL> raddr = ( "<STR_LIT>" , <NUM_LIT> ) , status = "<STR_LIT>" , pid = None ) , <EOL> sconn ( fd = <NUM_LIT:3> , family = <NUM_LIT:10> , type = <NUM_LIT:1> , laddr = ( "<STR_LIT>" , <NUM_LIT> ) , raddr = ( ) , <EOL> status = "<STR_LIT>" , pid = <NUM_LIT> ) , <EOL> sconn ( fd = <NUM_LIT:3> , family = <NUM_LIT:2> , type = <NUM_LIT:1> , laddr = ( "<STR_LIT>" , <NUM_LIT> ) , <EOL> raddr = ( ) , status = "<STR_LIT>" , pid = <NUM_LIT> ) ] <EOL> mock_net . return_value = conns <EOL> mock_process . name . return_value = "<STR_LIT>" <EOL> result = self . _call ( <NUM_LIT> ) <EOL> self . assertTrue ( result ) <EOL> self . assertEqual ( mock_get_utility . call_count , <NUM_LIT:1> ) <EOL> mock_process . assert_called_once_with ( <NUM_LIT> ) <EOL> @ mock . patch ( "<STR_LIT>" ) <EOL> def test_access_denied_exception ( self , mock_net ) : <EOL> mock_net . side_effect = psutil . AccessDenied ( "<STR_LIT>" ) <EOL> self . assertFalse ( self . _call ( <NUM_LIT> ) ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> unittest . main ( ) </s>
