<s> import sys <EOL> import os <EOL> import unittest <EOL> from scrapy . item import Item , Field <EOL> from scrapy . utils . misc import load_object , arg_to_iter , walk_modules <EOL> __doctests__ = [ '<STR_LIT>' ] <EOL> class UtilsMiscTestCase ( unittest . TestCase ) : <EOL> def test_load_object ( self ) : <EOL> obj = load_object ( '<STR_LIT>' ) <EOL> assert obj is load_object <EOL> self . assertRaises ( ImportError , load_object , '<STR_LIT>' ) <EOL> self . assertRaises ( NameError , load_object , '<STR_LIT>' ) <EOL> def test_walk_modules ( self ) : <EOL> mods = walk_modules ( '<STR_LIT>' ) <EOL> expected = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] <EOL> self . assertEquals ( set ( [ m . __name__ for m in mods ] ) , set ( expected ) ) <EOL> mods = walk_modules ( '<STR_LIT>' ) <EOL> expected = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] <EOL> self . assertEquals ( set ( [ m . __name__ for m in mods ] ) , set ( expected ) ) <EOL> mods = walk_modules ( '<STR_LIT>' ) <EOL> expected = [ <EOL> '<STR_LIT>' , <EOL> ] <EOL> self . assertEquals ( set ( [ m . __name__ for m in mods ] ) , set ( expected ) ) <EOL> self . assertRaises ( ImportError , walk_modules , '<STR_LIT>' ) <EOL> def test_walk_modules_egg ( self ) : <EOL> egg = os . path . join ( os . path . dirname ( __file__ ) , '<STR_LIT>' ) <EOL> sys . path . append ( egg ) <EOL> try : <EOL> mods = walk_modules ( '<STR_LIT>' ) <EOL> expected = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ] <EOL> self . assertEquals ( set ( [ m . __name__ for m in mods ] ) , set ( expected ) ) <EOL> finally : <EOL> sys . path . remove ( egg ) <EOL> def test_arg_to_iter ( self ) : <EOL> class TestItem ( Item ) : <EOL> name = Field ( ) <EOL> assert hasattr ( arg_to_iter ( None ) , '<STR_LIT>' ) <EOL> assert hasattr ( arg_to_iter ( <NUM_LIT:100> ) , '<STR_LIT>' ) <EOL> assert hasattr ( arg_to_iter ( '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> assert hasattr ( arg_to_iter ( [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] ) , '<STR_LIT>' ) <EOL> assert hasattr ( arg_to_iter ( l for l in '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> self . assertEqual ( list ( arg_to_iter ( None ) ) , [ ] ) <EOL> self . assertEqual ( list ( arg_to_iter ( '<STR_LIT>' ) ) , [ '<STR_LIT>' ] ) <EOL> self . assertEqual ( list ( arg_to_iter ( <NUM_LIT:100> ) ) , [ <NUM_LIT:100> ] ) <EOL> self . assertEqual ( list ( arg_to_iter ( l for l in '<STR_LIT:abc>' ) ) , [ '<STR_LIT:a>' , '<STR_LIT:b>' , '<STR_LIT:c>' ] ) <EOL> self . assertEqual ( list ( arg_to_iter ( [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] ) ) , [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] ) <EOL> self . assertEqual ( list ( arg_to_iter ( { '<STR_LIT:a>' : <NUM_LIT:1> } ) ) , [ { '<STR_LIT:a>' : <NUM_LIT:1> } ] ) <EOL> self . assertEqual ( list ( arg_to_iter ( TestItem ( name = "<STR_LIT>" ) ) ) , [ TestItem ( name = "<STR_LIT>" ) ] ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> unittest . main ( ) </s>
