<s> import contextlib <EOL> import os <EOL> import sys <EOL> import unittest <EOL> from pikos . runner import get_function , get_focused_on <EOL> def module_function ( ) : <EOL> pass <EOL> class DummyClass ( object ) : <EOL> def method ( self ) : <EOL> pass <EOL> class TestRunner ( unittest . TestCase ) : <EOL> def test_get_module_level_function ( self ) : <EOL> function = get_function ( '<STR_LIT>' ) <EOL> self . assertEqual ( function . func_code , module_function . func_code ) <EOL> def test_get_class_level_function ( self ) : <EOL> function = get_function ( <EOL> '<STR_LIT>' ) <EOL> self . assertEqual ( function . func_code , DummyClass . method . func_code ) <EOL> def test_focused_on_script_method ( self ) : <EOL> filename = self . _script_file ( ) <EOL> with self . _python_path ( filename ) : <EOL> functions = get_focused_on ( filename , '<STR_LIT>' ) <EOL> self . assertEqual ( len ( functions ) , <NUM_LIT:1> ) <EOL> function = functions [ <NUM_LIT:0> ] <EOL> self . assertEqual ( function . func_code , module_function . func_code ) <EOL> def test_get_focused_on_script_class_method ( self ) : <EOL> filename = self . _script_file ( ) <EOL> with self . _python_path ( filename ) : <EOL> functions = get_focused_on ( filename , '<STR_LIT>' ) <EOL> self . assertEqual ( len ( functions ) , <NUM_LIT:1> ) <EOL> function = functions [ <NUM_LIT:0> ] <EOL> self . assertEqual ( function . func_code , DummyClass . method . func_code ) <EOL> def test_get_focused_with_multiple_functions ( self ) : <EOL> filename = self . _script_file ( ) <EOL> with self . _python_path ( filename ) : <EOL> functions = get_focused_on ( <EOL> filename , '<STR_LIT>' ) <EOL> self . assertEqual ( len ( functions ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( <EOL> [ functions [ <NUM_LIT:0> ] . func_code , functions [ <NUM_LIT:1> ] . func_code ] , <EOL> [ module_function . func_code , DummyClass . method . func_code ] ) <EOL> def _script_file ( self ) : <EOL> module_file = os . path . splitext ( __file__ ) [ <NUM_LIT:0> ] <EOL> return '<STR_LIT:.>' . join ( ( module_file , '<STR_LIT>' ) ) <EOL> @ contextlib . contextmanager <EOL> def _python_path ( self , path ) : <EOL> self = os . path . dirname ( path ) <EOL> sys . path . insert ( <NUM_LIT:0> , self ) <EOL> try : <EOL> yield <EOL> finally : <EOL> sys . path . remove ( self ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
