<s> import pytest <EOL> from unittest . mock import MagicMock <EOL> @ pytest . fixture <EOL> def browser_commands ( ) : <EOL> from roland . core import BrowserCommands <EOL> commands = BrowserCommands ( ) <EOL> commands . roland = MagicMock ( ) <EOL> commands . webview = MagicMock ( ) <EOL> commands . entry_line = MagicMock ( ) <EOL> return commands <EOL> @ pytest . fixture <EOL> def real_browser_commands ( ) : <EOL> from roland . core import BrowserCommands , WebKit2 <EOL> commands = BrowserCommands ( ) <EOL> commands . webview = WebKit2 . WebView ( ) <EOL> return commands <EOL> @ pytest . fixture <EOL> def browser_window ( ) : <EOL> from roland . core import BrowserWindow <EOL> return BrowserWindow ( roland = MagicMock ( ) ) <EOL> class TestBrowserCommands : <EOL> @ pytest . mark . parametrize ( '<STR_LIT>' , [ <EOL> ( '<STR_LIT>' , False ) , <EOL> ( None , False ) , <EOL> ( '<STR_LIT>' , True ) , <EOL> ( None , True ) , <EOL> ( '<STR_LIT>' , True ) , <EOL> ( '<STR_LIT>' , False ) , <EOL> ] ) <EOL> def test_open ( self , url , new_window , browser_commands ) : <EOL> if url is None : <EOL> browser_commands . entry_line . prompt = lambda func , * args , ** kwargs : func ( '<STR_LIT>' ) <EOL> url = '<STR_LIT>' <EOL> else : <EOL> browser_commands . entry_line . prompt = lambda func , * args , ** kwargs : func ( url ) <EOL> browser_commands . open ( url , new_window ) <EOL> if new_window : <EOL> browser_commands . roland . new_window . assert_call ( url ) <EOL> else : <EOL> browser_commands . webview . load_uri . assert_any_call ( url ) <EOL> @ pytest . mark . parametrize ( '<STR_LIT>' , [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] ) <EOL> def test_real_commands_exist ( self , command , real_browser_commands ) : <EOL> command = getattr ( real_browser_commands , command ) <EOL> real_browser_commands . roland = MagicMock ( ) <EOL> command ( ) <EOL> @ pytest . mark . parametrize ( '<STR_LIT>' , [ <EOL> ( None , True , True ) , <EOL> ( '<STR_LIT:text>' , True , False ) , <EOL> ( '<STR_LIT:text>' , False , True ) , <EOL> ( '<STR_LIT>' , False , None ) , <EOL> ] ) <EOL> def test_search_page ( self , browser_commands , text , forwards , case_insensitive ) : <EOL> from gi . repository import WebKit2 <EOL> if text is None : <EOL> browser_commands . entry_line . prompt = lambda func , * args , ** kwargs : func ( '<STR_LIT>' ) <EOL> text = '<STR_LIT>' <EOL> else : <EOL> browser_commands . entry_line . prompt = lambda func , * args , ** kwargs : func ( text ) <EOL> browser_commands . search_page ( text , forwards = forwards , case_insensitive = case_insensitive ) <EOL> options = WebKit2 . FindOptions . WRAP_AROUND <EOL> if not forwards : <EOL> options |= WebKit2 . FindOptions . BACKWARDS <EOL> if case_insensitive is None : <EOL> case_insensitive = text . lower ( ) != text <EOL> if case_insensitive : <EOL> options |= WebKit2 . FindOptions . CASE_INSENSITIVE <EOL> finder = browser_commands . webview . get_find_controller . return_value <EOL> finder . search . assert_any_call ( text , options , <NUM_LIT:1000> ) <EOL> @ pytest . mark . parametrize ( '<STR_LIT>' , [ <EOL> ( False , False ) , <EOL> ( False , True ) , <EOL> ( True , False ) , <EOL> ( True , True ) , <EOL> ] ) <EOL> def test_next_search_result ( self , browser_commands , forwards , search_forwards ) : <EOL> browser_commands . search_forwards = search_forwards <EOL> finder = browser_commands . webview . get_find_controller . return_value <EOL> browser_commands . next_search_result ( forwards ) <EOL> if forwards == search_forwards : <EOL> finder . search_next . assert_has_call ( ) <EOL> else : <EOL> finder . search_prev . assert_has_call ( ) <EOL> class TestBrowserWindow : <EOL> @ pytest . mark . parametrize ( '<STR_LIT>' , [ <EOL> ( '<STR_LIT>' , False ) , <EOL> ( '<STR_LIT>' , True ) , <EOL> ] ) <EOL> def test_run_command ( self , command , expected_exist , browser_window ) : <EOL> if expected_exist : <EOL> setattr ( browser_window , command , MagicMock ( side_effect = Exception ( '<STR_LIT>' ) ) ) <EOL> browser_window . run_command ( command ) <EOL> browser_window . roland . notify . assert_has_call ( "<STR_LIT>" . format ( command ) ) <EOL> if expected_exist : <EOL> browser_window . roland . notify . assert_has_call ( "<STR_LIT>" . format ( command , '<STR_LIT>' ) ) <EOL> def test_failed_to_find_text ( self , browser_window ) : <EOL> finder = MagicMock ( ) <EOL> finder . get_search_text . return_value = None <EOL> browser_window . failed_to_find_text ( finder ) <EOL> assert not browser_window . roland . notify . mock_calls </s>
