<s> """<STR_LIT>""" <EOL> import os . path as op <EOL> import shutil <EOL> from . . format_manager import FormatManager , format_manager <EOL> from ... utils . tempdir import TemporaryDirectory <EOL> def load_mock ( path ) : <EOL> with open ( path , '<STR_LIT:r>' ) as f : <EOL> return [ line . rstrip ( ) for line in f . readlines ( ) [ <NUM_LIT:1> : ] ] <EOL> def save_mock ( path , contents ) : <EOL> with open ( path , '<STR_LIT:w>' ) as f : <EOL> f . write ( '<STR_LIT>' ) <EOL> f . write ( '<STR_LIT:\n>' . join ( contents ) ) <EOL> class MockReader ( object ) : <EOL> def read ( self , contents ) : <EOL> return [ { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:source>' : line } for line in contents ] <EOL> class MockWriter ( object ) : <EOL> def __init__ ( self ) : <EOL> self . contents = [ ] <EOL> def write ( self , cell ) : <EOL> if cell [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> self . contents . append ( cell [ '<STR_LIT:source>' ] ) <EOL> def test_format_manager ( ) : <EOL> fm = format_manager ( ) <EOL> fm . register ( name = '<STR_LIT>' , <EOL> reader = MockReader , <EOL> writer = MockWriter , <EOL> file_extension = '<STR_LIT>' , <EOL> load = load_mock , <EOL> save = save_mock ) <EOL> contents = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> with TemporaryDirectory ( ) as tempdir : <EOL> path = op . join ( tempdir , '<STR_LIT>' ) <EOL> fm . save ( path , contents ) <EOL> loaded = fm . load ( path ) <EOL> assert loaded == contents <EOL> fm . save ( path , loaded ) <EOL> with open ( path , '<STR_LIT:r>' ) as f : <EOL> assert f . read ( ) == '<STR_LIT>' <EOL> cells = fm . convert ( contents , from_ = '<STR_LIT>' ) <EOL> assert cells == [ { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:source>' : line } for line in contents ] <EOL> assert fm . convert ( cells , to = '<STR_LIT>' ) == contents <EOL> fm . unregister ( '<STR_LIT>' ) </s>
