<s> from os import getcwd , listdir <EOL> from os . path import abspath , dirname , isdir , join as path_join <EOL> from shutil import rmtree <EOL> from sys import exc_info <EOL> from tempfile import mkdtemp <EOL> from unittest import TestCase <EOL> from mock import patch , MagicMock <EOL> from robot . libraries . BuiltIn import BuiltIn <EOL> CURDIR = abspath ( dirname ( __file__ ) ) <EOL> class TestScreenshot ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . mock = MagicMock ( ) <EOL> self . patcher = patch . dict ( '<STR_LIT>' , { '<STR_LIT>' : self . mock } ) <EOL> self . patcher . start ( ) <EOL> from ImageHorizonLibrary import ImageHorizonLibrary <EOL> self . lib = ImageHorizonLibrary ( ) <EOL> def tearDown ( self ) : <EOL> self . mock . reset_mock ( ) <EOL> self . patcher . stop ( ) <EOL> def _take_screenshot_many_times ( self , expected_filename ) : <EOL> folder = path_join ( CURDIR , '<STR_LIT>' ) <EOL> self . lib . set_screenshot_folder ( folder ) <EOL> for i in range ( <NUM_LIT:1> , <NUM_LIT:15> ) : <EOL> self . lib . take_a_screenshot ( ) <EOL> self . mock . screenshot . assert_called_once_with ( <EOL> path_join ( folder , expected_filename % i ) ) <EOL> self . mock . reset_mock ( ) <EOL> def test_take_a_screenshot ( self ) : <EOL> self . _take_screenshot_many_times ( '<STR_LIT>' ) <EOL> def test_take_a_screenshot_inside_robot ( self ) : <EOL> with patch . object ( BuiltIn , '<STR_LIT>' , <EOL> return_value = '<STR_LIT>' ) : <EOL> self . _take_screenshot_many_times ( '<STR_LIT>' ) <EOL> def test_take_a_screenshot_with_invalid_folder ( self ) : <EOL> from ImageHorizonLibrary import ScreenshotFolderException <EOL> for index , invalid_folder in enumerate ( ( None , <NUM_LIT:0> , False ) , <NUM_LIT:1> ) : <EOL> self . lib . screenshot_folder = invalid_folder <EOL> expected = path_join ( getcwd ( ) , <EOL> '<STR_LIT>' % index ) <EOL> self . lib . take_a_screenshot ( ) <EOL> self . mock . screenshot . assert_called_once_with ( expected ) <EOL> self . mock . reset_mock ( ) <EOL> for invalid_folder in ( <NUM_LIT> , object ( ) ) : <EOL> self . lib . screenshot_folder = invalid_folder <EOL> with self . assertRaises ( ScreenshotFolderException ) : <EOL> self . lib . take_a_screenshot ( ) </s>
