<s> import unittest <EOL> from collections import Mapping <EOL> from array import array <EOL> try : <EOL> from UserDict import UserDict <EOL> from UserList import UserList <EOL> from UserString import UserString <EOL> except ImportError : <EOL> from collections import UserDict , UserList , UserString <EOL> try : <EOL> import java <EOL> from java . lang import String <EOL> from java . util import HashMap , Hashtable <EOL> except ImportError : <EOL> pass <EOL> from robot . utils import ( is_bytes , is_dict_like , is_list_like , is_string , <EOL> type_name , JYTHON , PY3 ) <EOL> from robot . utils . asserts import assert_equal <EOL> if PY3 : <EOL> long = int <EOL> class MyMapping ( Mapping ) : <EOL> def __getitem__ ( self , item ) : <EOL> return <NUM_LIT:0> <EOL> def __len__ ( self ) : <EOL> return <NUM_LIT:0> <EOL> def __iter__ ( self ) : <EOL> return iter ( [ ] ) <EOL> def generator ( ) : <EOL> yield '<STR_LIT>' <EOL> class TestStringsAndBytes ( unittest . TestCase ) : <EOL> def test_strings ( self ) : <EOL> for thing in [ '<STR_LIT:string>' , u'<STR_LIT>' , '<STR_LIT>' , u'<STR_LIT>' ] : <EOL> assert_equal ( is_string ( thing ) , True , thing ) <EOL> assert_equal ( is_bytes ( thing ) , isinstance ( thing , bytes ) ) <EOL> def test_bytes ( self ) : <EOL> for thing in [ b'<STR_LIT>' , bytearray ( b'<STR_LIT>' ) , b'<STR_LIT>' , bytearray ( ) ] : <EOL> assert_equal ( is_bytes ( thing ) , True , thing ) <EOL> assert_equal ( is_string ( thing ) , isinstance ( thing , str ) ) <EOL> class TestListLike ( unittest . TestCase ) : <EOL> def test_strings_are_not_list_like ( self ) : <EOL> for thing in [ '<STR_LIT:str>' , u'<STR_LIT>' , UserString ( '<STR_LIT:user>' ) ] : <EOL> assert_equal ( is_list_like ( thing ) , False , thing ) <EOL> def test_bytes_are_not_list_like ( self ) : <EOL> for thing in [ b'<STR_LIT>' , bytearray ( b'<STR_LIT>' ) ] : <EOL> assert_equal ( is_list_like ( thing ) , False , thing ) <EOL> def test_dict_likes_are_list_like ( self ) : <EOL> for thing in [ dict ( ) , UserDict ( ) , MyMapping ( ) ] : <EOL> assert_equal ( is_list_like ( thing ) , True , thing ) <EOL> if JYTHON : <EOL> def test_java_strings_are_not_list_like ( self ) : <EOL> assert_equal ( is_list_like ( String ( ) ) , False ) <EOL> def test_java_dict_likes_are_list_like ( self ) : <EOL> assert_equal ( is_list_like ( HashMap ( ) ) , True ) <EOL> assert_equal ( is_list_like ( Hashtable ( ) ) , True ) <EOL> def test_files_are_not_list_like ( self ) : <EOL> with open ( __file__ ) as f : <EOL> assert_equal ( is_list_like ( f ) , False ) <EOL> assert_equal ( is_list_like ( f ) , False ) <EOL> def test_object_raising_exception_are_not_list_like ( self ) : <EOL> class O ( object ) : <EOL> def __iter__ ( self ) : <EOL> <NUM_LIT:1> / <NUM_LIT:0> <EOL> assert_equal ( is_list_like ( O ( ) ) , False ) <EOL> def test_other_iterables_are_list_like ( self ) : <EOL> try : <EOL> xrange <EOL> except NameError : <EOL> xrange = range <EOL> for thing in [ [ ] , ( ) , set ( ) , xrange ( <NUM_LIT:1> ) , generator ( ) , array ( '<STR_LIT:i>' ) , UserList ( ) ] : <EOL> assert_equal ( is_list_like ( thing ) , True , thing ) <EOL> def test_others_are_not_list_like ( self ) : <EOL> for thing in [ <NUM_LIT:1> , None , True , object ( ) ] : <EOL> assert_equal ( is_list_like ( thing ) , False , thing ) <EOL> def test_generators_are_not_consumed ( self ) : <EOL> g = generator ( ) <EOL> assert_equal ( is_list_like ( g ) , True ) <EOL> assert_equal ( is_list_like ( g ) , True ) <EOL> assert_equal ( list ( g ) , [ '<STR_LIT>' ] ) <EOL> assert_equal ( list ( g ) , [ ] ) <EOL> assert_equal ( is_list_like ( g ) , True ) <EOL> class TestDictLike ( unittest . TestCase ) : <EOL> def test_dict_likes ( self ) : <EOL> for thing in [ dict ( ) , UserDict ( ) , MyMapping ( ) ] : <EOL> assert_equal ( is_dict_like ( thing ) , True , thing ) <EOL> def test_others ( self ) : <EOL> for thing in [ '<STR_LIT>' , u'<STR_LIT>' , <NUM_LIT:1> , None , True , object ( ) , [ ] , ( ) , set ( ) ] : <EOL> assert_equal ( is_dict_like ( thing ) , False , thing ) <EOL> if JYTHON : <EOL> def test_java_maps ( self ) : <EOL> assert_equal ( is_dict_like ( HashMap ( ) ) , True ) <EOL> assert_equal ( is_dict_like ( Hashtable ( ) ) , True ) <EOL> class TestTypeName ( unittest . TestCase ) : <EOL> def test_base_types ( self ) : <EOL> for item , exp in [ ( '<STR_LIT>' , '<STR_LIT:string>' ) , ( u'<STR_LIT>' , '<STR_LIT:string>' ) , <EOL> ( b'<STR_LIT>' , '<STR_LIT:string>' if bytes is str else '<STR_LIT>' ) , <EOL> ( bytearray ( ) , '<STR_LIT>' ) , <EOL> ( <NUM_LIT:1> , '<STR_LIT>' ) , ( long ( <NUM_LIT:1> ) , '<STR_LIT>' ) , ( <NUM_LIT:1.0> , '<STR_LIT:float>' ) , <EOL> ( True , '<STR_LIT>' ) , ( None , '<STR_LIT:None>' ) , ( set ( ) , '<STR_LIT>' ) , <EOL> ( [ ] , '<STR_LIT:list>' ) , ( ( ) , '<STR_LIT>' ) , ( { } , '<STR_LIT>' ) ] : <EOL> assert_equal ( type_name ( item ) , exp ) <EOL> def test_file ( self ) : <EOL> with open ( __file__ ) as f : <EOL> assert_equal ( type_name ( f ) , '<STR_LIT:file>' ) <EOL> def test_custom_objects ( self ) : <EOL> class NewStyle ( object ) : pass <EOL> class OldStyle : pass <EOL> for item , exp in [ ( NewStyle ( ) , '<STR_LIT>' ) , ( OldStyle ( ) , '<STR_LIT>' ) , <EOL> ( NewStyle , '<STR_LIT:class>' ) , ( OldStyle , '<STR_LIT:class>' ) ] : <EOL> assert_equal ( type_name ( item ) , exp ) <EOL> if JYTHON : <EOL> def test_java_object ( self ) : <EOL> for item , exp in [ ( String ( ) , '<STR_LIT>' ) , ( String , '<STR_LIT>' ) , <EOL> ( java . lang , '<STR_LIT>' ) , ( java , '<STR_LIT>' ) ] : <EOL> assert_equal ( type_name ( item ) , exp ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
