<s> import os <EOL> from unittest import TestCase <EOL> from sklearn . base import BaseEstimator <EOL> try : <EOL> import cPickle as pickle <EOL> except : <EOL> import pickle <EOL> from sklearn_pmml . convert import * <EOL> from sklearn_pmml import pmml <EOL> class TestSerializationMeta ( type ) : <EOL> TEST_DIR = os . path . dirname ( __file__ ) <EOL> DATA_DIR = os . path . join ( TEST_DIR , '<STR_LIT:data>' ) <EOL> ESTIMATOR_FILE_NAME = '<STR_LIT>' <EOL> PMML_FILE_NAME = '<STR_LIT>' <EOL> CONTEXT_FILE_NAME = '<STR_LIT>' <EOL> def __new__ ( mcs , name , bases , d ) : <EOL> """<STR_LIT>""" <EOL> def gen_test ( suite_name ) : <EOL> def load_and_compare ( self ) : <EOL> suite_path = os . path . join ( mcs . DATA_DIR , suite_name ) <EOL> content = os . listdir ( suite_path ) <EOL> assert len ( content ) == <NUM_LIT:3> , '<STR_LIT>' <EOL> assert mcs . ESTIMATOR_FILE_NAME in content , '<STR_LIT>' . format ( mcs . ESTIMATOR_FILE_NAME ) <EOL> assert mcs . PMML_FILE_NAME in content , '<STR_LIT>' . format ( mcs . PMML_FILE_NAME ) <EOL> assert mcs . CONTEXT_FILE_NAME in content , '<STR_LIT>' . format ( mcs . CONTEXT_FILE_NAME ) <EOL> with open ( os . path . join ( suite_path , mcs . ESTIMATOR_FILE_NAME ) , '<STR_LIT:r>' ) as est_file : <EOL> est = pickle . load ( est_file ) <EOL> assert isinstance ( est , BaseEstimator ) , '<STR_LIT>' . format ( mcs . ESTIMATOR_FILE_NAME ) <EOL> with open ( os . path . join ( suite_path , mcs . CONTEXT_FILE_NAME ) , '<STR_LIT:r>' ) as ctx_file : <EOL> ctx = pickle . load ( ctx_file ) <EOL> assert isinstance ( ctx , TransformationContext ) , '<STR_LIT>' . format ( mcs . CONTEXT_FILE_NAME ) <EOL> converter = find_converter ( est ) <EOL> assert converter is not None , '<STR_LIT>' . format ( est ) <EOL> transformed_pmml = converter ( est , ctx ) . pmml ( ) <EOL> with open ( os . path . join ( suite_path , mcs . PMML_FILE_NAME ) , '<STR_LIT:r>' ) as pmml_file : <EOL> loaded_pmml = pmml . CreateFromDocument ( '<STR_LIT:\n>' . join ( pmml_file . readlines ( ) ) ) <EOL> self . maxDiff = None <EOL> self . assertEquals ( loaded_pmml . toDOM ( ) . toprettyxml ( ) , transformed_pmml . toDOM ( ) . toprettyxml ( ) ) <EOL> return load_and_compare <EOL> for case in os . listdir ( TestSerializationMeta . DATA_DIR ) : <EOL> test_name = '<STR_LIT>' . format ( case ) <EOL> d [ test_name ] = gen_test ( case ) <EOL> return type . __new__ ( mcs , name , bases , d ) <EOL> class TestSerialization ( TestCase ) : <EOL> """<STR_LIT>""" <EOL> __metaclass__ = TestSerializationMeta </s>
