<s> import unittest <EOL> from inmemorystorage import InMemoryStorage <EOL> from inmemorystorage . storage import InMemoryDir , InMemoryFile <EOL> from django . core . files . base import ContentFile <EOL> class MemoryStorageTests ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . storage = InMemoryStorage ( ) <EOL> self . filesystem = self . storage . filesystem <EOL> def test_listdir ( self ) : <EOL> self . assertEqual ( self . storage . listdir ( '<STR_LIT>' ) , [ [ ] , [ ] ] ) <EOL> self . filesystem . add_child ( '<STR_LIT>' , InMemoryDir ( ) ) <EOL> self . filesystem . add_child ( '<STR_LIT>' , InMemoryFile ( ) ) <EOL> self . assertEqual ( self . storage . listdir ( '<STR_LIT>' ) , [ [ '<STR_LIT>' ] , [ '<STR_LIT>' ] ] ) <EOL> self . assertEqual ( self . storage . listdir ( '<STR_LIT>' ) , [ [ ] , [ ] ] ) <EOL> self . filesystem . resolve ( '<STR_LIT>' ) . add_child ( '<STR_LIT>' , InMemoryDir ( ) ) <EOL> self . assertEqual ( self . storage . listdir ( '<STR_LIT>' ) , [ [ '<STR_LIT>' ] , [ ] ] ) <EOL> def test_delete ( self ) : <EOL> self . filesystem . add_child ( '<STR_LIT>' , InMemoryDir ( ) ) <EOL> self . filesystem . resolve ( '<STR_LIT>' ) . add_child ( '<STR_LIT>' , InMemoryFile ( ) ) <EOL> self . filesystem . add_child ( '<STR_LIT>' , InMemoryFile ( ) ) <EOL> self . assertEqual ( self . filesystem . resolve ( '<STR_LIT>' ) . ls ( ) , [ '<STR_LIT>' ] ) <EOL> self . storage . delete ( '<STR_LIT>' ) <EOL> self . assertEqual ( self . filesystem . resolve ( '<STR_LIT>' ) . ls ( ) , [ ] ) <EOL> self . assertEqual ( set ( self . filesystem . ls ( ) ) , set ( [ '<STR_LIT>' , '<STR_LIT>' ] ) ) <EOL> self . storage . delete ( '<STR_LIT>' ) <EOL> self . assertEqual ( set ( self . filesystem . ls ( ) ) , set ( [ '<STR_LIT>' ] ) ) <EOL> def test_exists ( self ) : <EOL> self . filesystem . add_child ( '<STR_LIT>' , InMemoryFile ( ) ) <EOL> self . assertTrue ( self . storage . exists ( '<STR_LIT>' ) ) <EOL> self . assertFalse ( self . storage . exists ( '<STR_LIT>' ) ) <EOL> self . storage . delete ( '<STR_LIT>' ) <EOL> self . assertFalse ( self . storage . exists ( '<STR_LIT>' ) ) <EOL> def test_size ( self ) : <EOL> self . filesystem . add_child ( '<STR_LIT>' , InMemoryFile ( '<STR_LIT:test>' ) ) <EOL> self . assertEqual ( self . storage . size ( '<STR_LIT>' ) , <NUM_LIT:4> ) <EOL> def test_save ( self ) : <EOL> self . storage . save ( '<STR_LIT:file>' , ContentFile ( '<STR_LIT:test>' ) ) <EOL> self . assertEqual ( self . storage . size ( '<STR_LIT:file>' ) , <NUM_LIT:4> ) <EOL> self . storage . save ( '<STR_LIT>' , ContentFile ( '<STR_LIT:test>' ) ) <EOL> self . assertEqual ( self . storage . size ( '<STR_LIT>' ) , <NUM_LIT:4> ) <EOL> def test_all ( self ) : <EOL> self . assertEqual ( self . storage . listdir ( '<STR_LIT:/>' ) , [ [ ] , [ ] ] ) <EOL> self . assertEqual ( self . storage . save ( '<STR_LIT>' , ContentFile ( '<STR_LIT>' ) ) , '<STR_LIT>' ) <EOL> self . assertEqual ( self . storage . listdir ( '<STR_LIT:/>' ) , [ [ '<STR_LIT>' ] , [ ] ] ) <EOL> self . assertEqual ( self . storage . listdir ( '<STR_LIT>' ) , [ [ '<STR_LIT>' ] , [ ] ] ) <EOL> self . assertEqual ( self . storage . save ( '<STR_LIT>' , ContentFile ( '<STR_LIT>' ) ) , '<STR_LIT>' ) <EOL> self . assertEqual ( self . storage . save ( '<STR_LIT:file>' , ContentFile ( '<STR_LIT>' ) ) , '<STR_LIT:file>' ) <EOL> self . assertEqual ( self . storage . listdir ( '<STR_LIT:/>' ) , [ [ '<STR_LIT>' ] , [ '<STR_LIT:file>' ] ] ) <EOL> self . assertEqual ( self . storage . listdir ( '<STR_LIT>' ) , [ [ '<STR_LIT>' ] , [ ] ] ) <EOL> self . assertEqual ( self . storage . open ( '<STR_LIT>' ) . read ( ) , '<STR_LIT>' ) <EOL> self . assertEqual ( self . storage . size ( '<STR_LIT>' ) , <NUM_LIT:7> ) <EOL> self . assertEqual ( self . storage . size ( '<STR_LIT>' ) , <NUM_LIT:8> ) <EOL> self . assertEqual ( self . storage . size ( '<STR_LIT:file>' ) , <NUM_LIT:8> ) <EOL> self . assertEqual ( self . storage . delete ( '<STR_LIT:file>' ) , None ) <EOL> self . assertEqual ( self . storage . listdir ( '<STR_LIT:/>' ) , [ [ '<STR_LIT>' ] , [ ] ] ) <EOL> self . assertEqual ( self . storage . delete ( '<STR_LIT>' ) , None ) <EOL> self . assertEqual ( self . storage . listdir ( '<STR_LIT>' ) , [ [ ] , [ '<STR_LIT>' ] ] ) <EOL> self . assertEqual ( self . storage . exists ( '<STR_LIT>' ) , True ) <EOL> self . assertEqual ( self . storage . delete ( '<STR_LIT>' ) , None ) <EOL> self . assertEqual ( self . storage . exists ( '<STR_LIT>' ) , False ) <EOL> self . assertEqual ( self . storage . listdir ( '<STR_LIT>' ) , [ [ ] , [ ] ] ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
