<s> try : <EOL> from functools import reduce <EOL> except ImportError : <EOL> pass <EOL> import six <EOL> import sys <EOL> import unittest <EOL> from nose . tools import eq_ <EOL> from nose . tools import ok_ <EOL> from ryu . ofproto import ofproto_v1_5 <EOL> from ryu . ofproto import ofproto_v1_5_parser <EOL> from ryu . tests import test_lib <EOL> class Test_Parser_OFPStats ( unittest . TestCase ) : <EOL> _ofp = { ofproto_v1_5_parser : ofproto_v1_5 } <EOL> def __init__ ( self , methodName ) : <EOL> print ( '<STR_LIT>' % methodName ) <EOL> super ( Test_Parser_OFPStats , self ) . __init__ ( methodName ) <EOL> def setUp ( self ) : <EOL> pass <EOL> def tearDown ( self ) : <EOL> pass <EOL> def _test ( self , name , ofpp , d ) : <EOL> stats = ofpp . OFPStats ( ** d ) <EOL> b = bytearray ( ) <EOL> stats . serialize ( b , <NUM_LIT:0> ) <EOL> stats2 = stats . parser ( six . binary_type ( b ) , <NUM_LIT:0> ) <EOL> for k , v in d . items ( ) : <EOL> ok_ ( k in stats ) <EOL> ok_ ( k in stats2 ) <EOL> eq_ ( stats [ k ] , v ) <EOL> eq_ ( stats2 [ k ] , v ) <EOL> for k , v in stats . iteritems ( ) : <EOL> ok_ ( k in d ) <EOL> eq_ ( d [ k ] , v ) <EOL> for k , v in stats2 . iteritems ( ) : <EOL> ok_ ( k in d ) <EOL> eq_ ( d [ k ] , v ) <EOL> def _add_tests ( ) : <EOL> import functools <EOL> import itertools <EOL> class Field ( object ) : <EOL> pass <EOL> class Int1 ( Field ) : <EOL> @ staticmethod <EOL> def generate ( ) : <EOL> yield <NUM_LIT:0> <EOL> yield <NUM_LIT> <EOL> class Int2 ( Field ) : <EOL> @ staticmethod <EOL> def generate ( ) : <EOL> yield <NUM_LIT:0> <EOL> yield <NUM_LIT> <EOL> yield <NUM_LIT> <EOL> class Int3 ( Field ) : <EOL> @ staticmethod <EOL> def generate ( ) : <EOL> yield <NUM_LIT:0> <EOL> yield <NUM_LIT> <EOL> yield <NUM_LIT> <EOL> class Int4 ( Field ) : <EOL> @ staticmethod <EOL> def generate ( ) : <EOL> yield <NUM_LIT:0> <EOL> yield <NUM_LIT> <EOL> yield <NUM_LIT> <EOL> class Int4double ( Field ) : <EOL> @ staticmethod <EOL> def generate ( ) : <EOL> yield [ <NUM_LIT:0> , <NUM_LIT:1> ] <EOL> yield [ <NUM_LIT> , <NUM_LIT> ] <EOL> yield [ <NUM_LIT> , <NUM_LIT> ] <EOL> class Int8 ( Field ) : <EOL> @ staticmethod <EOL> def generate ( ) : <EOL> yield <NUM_LIT:0> <EOL> yield <NUM_LIT> <EOL> yield <NUM_LIT> <EOL> class Mac ( Field ) : <EOL> @ staticmethod <EOL> def generate ( ) : <EOL> yield '<STR_LIT>' <EOL> yield '<STR_LIT>' <EOL> yield '<STR_LIT>' <EOL> class IPv4 ( Field ) : <EOL> @ staticmethod <EOL> def generate ( ) : <EOL> yield '<STR_LIT>' <EOL> yield '<STR_LIT>' <EOL> yield '<STR_LIT>' <EOL> class IPv6 ( Field ) : <EOL> @ staticmethod <EOL> def generate ( ) : <EOL> yield '<STR_LIT>' <EOL> yield '<STR_LIT>' <EOL> yield '<STR_LIT>' <EOL> class B64 ( Field ) : <EOL> @ staticmethod <EOL> def generate ( ) : <EOL> yield '<STR_LIT>' <EOL> yield '<STR_LIT>' <EOL> ofpps = [ ofproto_v1_5_parser ] <EOL> common = [ <EOL> ( '<STR_LIT>' , Int4double ) , <EOL> ( '<STR_LIT>' , Int4double ) , <EOL> ( '<STR_LIT>' , Int4 ) , <EOL> ( '<STR_LIT>' , Int8 ) , <EOL> ( '<STR_LIT>' , Int8 ) , <EOL> ( '<STR_LIT>' , B64 ) , <EOL> ] <EOL> L = { } <EOL> L [ ofproto_v1_5_parser ] = common <EOL> def flatten_one ( l , i ) : <EOL> if isinstance ( i , tuple ) : <EOL> return l + flatten ( i ) <EOL> else : <EOL> return l + [ i ] <EOL> flatten = lambda l : reduce ( flatten_one , l , [ ] ) <EOL> for ofpp in ofpps : <EOL> for n in range ( <NUM_LIT:1> , <NUM_LIT:3> ) : <EOL> for C in itertools . combinations ( L [ ofpp ] , n ) : <EOL> l = [ <NUM_LIT:1> ] <EOL> keys = [ ] <EOL> clss = [ ] <EOL> for ( k , cls ) in C : <EOL> l = itertools . product ( l , cls . generate ( ) ) <EOL> keys . append ( k ) <EOL> clss . append ( cls ) <EOL> l = [ flatten ( x ) [ <NUM_LIT:1> : ] for x in l ] <EOL> for values in l : <EOL> d = dict ( zip ( keys , values ) ) <EOL> for n , uv in d . items ( ) : <EOL> if isinstance ( uv , list ) : <EOL> d [ n ] = tuple ( uv ) <EOL> mod = ofpp . __name__ . split ( '<STR_LIT:.>' ) [ - <NUM_LIT:1> ] <EOL> method_name = '<STR_LIT>' + mod <EOL> for k in sorted ( dict ( d ) . keys ( ) ) : <EOL> method_name += '<STR_LIT:_>' + str ( k ) <EOL> method_name += '<STR_LIT:_>' + str ( d [ k ] ) <EOL> method_name = method_name . replace ( '<STR_LIT::>' , '<STR_LIT:_>' ) <EOL> method_name = method_name . replace ( '<STR_LIT:.>' , '<STR_LIT:_>' ) <EOL> method_name = method_name . replace ( '<STR_LIT:(>' , '<STR_LIT:_>' ) <EOL> method_name = method_name . replace ( '<STR_LIT:)>' , '<STR_LIT:_>' ) <EOL> method_name = method_name . replace ( '<STR_LIT:U+002C>' , '<STR_LIT:_>' ) <EOL> method_name = method_name . replace ( "<STR_LIT:'>" , '<STR_LIT:_>' ) <EOL> method_name = method_name . replace ( '<STR_LIT:U+0020>' , '<STR_LIT:_>' ) <EOL> def _run ( self , name , ofpp , d ) : <EOL> print ( '<STR_LIT>' % name ) <EOL> if six . PY3 : <EOL> self . _test ( self , name , ofpp , d ) <EOL> else : <EOL> self . _test ( name , ofpp , d ) <EOL> print ( '<STR_LIT>' % method_name ) <EOL> f = functools . partial ( _run , name = method_name , <EOL> ofpp = ofpp , d = d ) <EOL> test_lib . add_method ( Test_Parser_OFPStats , <EOL> method_name , f ) <EOL> _add_tests ( ) </s>
