<s> import unittest <EOL> import datafilereader <EOL> from nose . tools import assert_equals <EOL> from robotide . usages . commands import FindResourceUsages <EOL> class ResourceUsageTests ( unittest . TestCase ) : <EOL> @ classmethod <EOL> def setUpClass ( cls ) : <EOL> cls . ctrl = datafilereader . construct_project ( datafilereader . SIMPLE_TEST_SUITE_PATH ) <EOL> cls . ts1 = datafilereader . get_ctrl_by_name ( '<STR_LIT>' , cls . ctrl . datafiles ) <EOL> cls . ts2 = datafilereader . get_ctrl_by_name ( '<STR_LIT>' , cls . ctrl . datafiles ) <EOL> cls . resu = datafilereader . get_ctrl_by_name ( datafilereader . SIMPLE_TEST_SUITE_RESOURCE_NAME , cls . ctrl . datafiles ) <EOL> @ classmethod <EOL> def tearDownClass ( cls ) : <EOL> cls . ctrl . close ( ) <EOL> def test_resource_import_knows_imported_resource_controller ( self ) : <EOL> assert_equals ( self . resu , self . ts1 . imports [ <NUM_LIT:0> ] . get_imported_controller ( ) ) <EOL> assert_equals ( self . resu , self . ts2 . imports [ <NUM_LIT:0> ] . get_imported_controller ( ) ) <EOL> def test_resource_usages_finding ( self ) : <EOL> usages = list ( self . resu . execute ( FindResourceUsages ( ) ) ) <EOL> self . _verify_length ( <NUM_LIT:2> , usages ) <EOL> self . _verify_that_contains ( self . ts1 , usages ) <EOL> self . _verify_that_contains ( self . ts2 , usages ) <EOL> def _verify_length ( self , expected , usages ) : <EOL> assert_equals ( len ( usages ) , expected ) <EOL> def _verify_that_contains ( self , item , usages ) : <EOL> for u in usages : <EOL> if u . item == item . imports : <EOL> if item . display_name != u . name : <EOL> raise AssertionError ( '<STR_LIT>' % ( u . name , item . display_name ) ) <EOL> return <EOL> raise AssertionError ( '<STR_LIT>' % ( item , usages ) ) <EOL> def test_import_in_resource_file ( self ) : <EOL> inner_resu = self . resu . imports [ <NUM_LIT:0> ] . get_imported_controller ( ) <EOL> usages = list ( inner_resu . execute ( FindResourceUsages ( ) ) ) <EOL> self . _verify_length ( <NUM_LIT:1> , usages ) <EOL> self . _verify_that_contains ( self . resu , usages ) <EOL> def test_none_existing_import ( self ) : <EOL> imp = self . ts1 . imports . add_resource ( '<STR_LIT>' ) <EOL> assert_equals ( imp . get_imported_controller ( ) , None ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
