<s> from . import FSQTestCase <EOL> from . internal import normalize <EOL> from . import constants as _test_c <EOL> from . . import encode , decode , constants as _c , FSQCoerceError , FSQEncodeError <EOL> class TestEncodeDecode ( FSQTestCase ) : <EOL> def _cycle ( self , arg , fsq_encode = None , fsq_delimiter = None , assert_eq = True , <EOL> ** kwargs ) : <EOL> normalize ( ) <EOL> if fsq_encode is not None : <EOL> _c . FSQ_ENCODE = fsq_encode <EOL> if fsq_delimiter is not None : <EOL> _c . FSQ_DELIMITER = fsq_delimiter <EOL> encoded = encode ( arg , ** kwargs ) <EOL> if kwargs . has_key ( '<STR_LIT>' ) : <EOL> del kwargs [ '<STR_LIT>' ] <EOL> decoded = decode ( encoded , ** kwargs ) <EOL> if assert_eq : <EOL> self . assertEquals ( decoded , arg ) <EOL> return decoded <EOL> def test_basic ( self ) : <EOL> for encodeseq , delimiter in ( _test_c . ORIG_ENCODE_DELIMITER , <EOL> ( _test_c . ENCODE , _test_c . DELIMITER , ) ) : <EOL> for i in _test_c . NORMAL + ( _c . FSQ_DELIMITER . join ( _test_c . NORMAL ) , <EOL> _c . FSQ_ENCODE . join ( _test_c . NORMAL ) , <EOL> _c . FSQ_ENCODE . join ( [ <EOL> _test_c . NON_ASCII ] * <NUM_LIT:2> ) , ) + _test_c . ILLEGAL_NAMES : <EOL> self . _cycle ( i , fsq_encode = encodeseq ) <EOL> self . _cycle ( i , fsq_delimiter = delimiter ) <EOL> self . _cycle ( i , fsq_encode = encodeseq , fsq_delimiter = delimiter ) <EOL> self . _cycle ( i , encodeseq = encodeseq ) <EOL> self . _cycle ( i , delimiter = delimiter ) <EOL> self . _cycle ( i , encodeseq = encodeseq , delimiter = delimiter ) <EOL> self . _cycle ( i , encoded = _test_c . ENCODED ) <EOL> self . _cycle ( i , encodeseq = encodeseq , encoded = _test_c . ENCODED ) <EOL> self . _cycle ( i , delimiter = delimiter , encoded = _test_c . ENCODED ) <EOL> self . _cycle ( i , encodeseq = encodeseq , delimiter = delimiter , <EOL> encoded = _test_c . ENCODED ) <EOL> for i in _test_c . MODES : <EOL> self . assertEquals ( unicode ( i ) , self . _cycle ( i , assert_eq = False ) ) <EOL> self . assertEquals ( unicode ( float ( i ) ) , self . _cycle ( float ( i ) , <EOL> assert_eq = False ) ) <EOL> def test_badencode ( self ) : <EOL> normalize ( ) <EOL> _c . FSQ_ENCODE = _test_c . ILLEGAL_ENCODE <EOL> self . assertRaises ( FSQEncodeError , encode , _test_c . NORMAL [ <NUM_LIT:0> ] ) <EOL> normalize ( ) <EOL> self . assertRaises ( FSQEncodeError , encode , _test_c . NORMAL [ <NUM_LIT:0> ] , <EOL> encodeseq = _test_c . ILLEGAL_ENCODE ) <EOL> normalize ( ) <EOL> _c . FSQ_ENCODE = _test_c . ILLEGAL_NAME <EOL> self . assertRaises ( FSQCoerceError , encode , _test_c . NORMAL [ <NUM_LIT:0> ] ) <EOL> normalize ( ) <EOL> self . assertRaises ( FSQCoerceError , encode , _test_c . NORMAL [ <NUM_LIT:0> ] , <EOL> encodeseq = _test_c . ILLEGAL_NAME ) <EOL> self . assertRaises ( FSQCoerceError , encode , _test_c . ILLEGAL_NAME ) <EOL> normalize ( ) <EOL> self . assertRaises ( FSQEncodeError , encode , _test_c . NORMAL [ <NUM_LIT:0> ] , <EOL> encoded = ( _test_c . NON_ASCII , ) ) <EOL> normalize ( ) <EOL> self . assertRaises ( FSQEncodeError , encode , _test_c . NORMAL [ <NUM_LIT:0> ] , <EOL> encodeseq = _test_c . NON_ASCII ) <EOL> normalize ( ) <EOL> self . assertRaises ( FSQEncodeError , encode , _test_c . NORMAL [ <NUM_LIT:0> ] , <EOL> delimiter = _test_c . NON_ASCII , ) <EOL> normalize ( ) <EOL> self . assertRaises ( FSQEncodeError , encode , _test_c . NORMAL [ <NUM_LIT:0> ] , <EOL> delimiter = _c . FSQ_ENCODE ) <EOL> def test_baddecode ( self ) : <EOL> normalize ( ) <EOL> _c . FSQ_ENCODE = _test_c . ILLEGAL_ENCODE <EOL> self . assertRaises ( FSQEncodeError , decode , _test_c . NORMAL [ <NUM_LIT:0> ] ) <EOL> normalize ( ) <EOL> self . assertRaises ( FSQEncodeError , decode , _test_c . NORMAL [ <NUM_LIT:0> ] , <EOL> encodeseq = _test_c . ILLEGAL_ENCODE ) <EOL> normalize ( ) <EOL> _c . FSQ_ENCODE = _test_c . ILLEGAL_NAME <EOL> self . assertRaises ( FSQCoerceError , decode , _test_c . NORMAL [ <NUM_LIT:0> ] ) <EOL> normalize ( ) <EOL> self . assertRaises ( FSQCoerceError , decode , _test_c . NORMAL [ <NUM_LIT:0> ] , <EOL> encodeseq = _test_c . ILLEGAL_NAME ) <EOL> self . assertRaises ( FSQEncodeError , decode , _c . FSQ_DELIMITER . join ( [ <EOL> _test_c . NORMAL [ <NUM_LIT:0> ] , _c . FSQ_ENCODE ] ) ) <EOL> bad_val = u'<STR_LIT>' . join ( [ _c . FSQ_ENCODE , hex ( ord ( _test_c . NON_ASCII ) ) ] ) <EOL> self . assertRaises ( FSQEncodeError , decode , bad_val ) <EOL> self . assertRaises ( FSQCoerceError , decode , _test_c . ILLEGAL_NAME ) </s>
