<s> from __future__ import print_function , absolute_import , division <EOL> import json <EOL> import shutil <EOL> import sys <EOL> import tempfile <EOL> import unittest <EOL> from argparse import Namespace <EOL> import numpy as np <EOL> from numpy . testing . decorators import skipif <EOL> try : <EOL> import pylearn2 <EOL> del pylearn2 <EOL> except ImportError : <EOL> pass <EOL> from osprey import execute_worker , execute_dump <EOL> from osprey . plugins . plugin_pylearn2 import Pylearn2DatasetLoader <EOL> class TestPluginPylearn2 ( unittest . TestCase ) : <EOL> """<STR_LIT>""" <EOL> def setUp ( self ) : <EOL> self . temp_dir = tempfile . mkdtemp ( ) <EOL> def tearDown ( self ) : <EOL> shutil . rmtree ( self . temp_dir ) <EOL> def run_osprey ( self , config ) : <EOL> """<STR_LIT>""" <EOL> fh , filename = tempfile . mkstemp ( dir = self . temp_dir ) <EOL> with open ( filename , '<STR_LIT:wb>' ) as f : <EOL> f . write ( config ) <EOL> args = Namespace ( config = filename , n_iters = <NUM_LIT:1> , output = '<STR_LIT>' ) <EOL> execute_worker . execute ( args , None ) <EOL> dump = json . loads ( execute_dump . execute ( args , None ) ) <EOL> assert len ( dump ) == <NUM_LIT:1> <EOL> assert dump [ <NUM_LIT:0> ] [ '<STR_LIT:status>' ] == '<STR_LIT>' , dump [ <NUM_LIT:0> ] [ '<STR_LIT:status>' ] <EOL> @ skipif ( '<STR_LIT>' not in sys . modules , '<STR_LIT>' ) <EOL> def test_pylearn2_classifier ( self ) : <EOL> config = """<STR_LIT>""" <EOL> self . run_osprey ( config ) <EOL> @ skipif ( '<STR_LIT>' not in sys . modules , '<STR_LIT>' ) <EOL> def test_pylearn2_regressor ( self ) : <EOL> config = """<STR_LIT>""" <EOL> self . run_osprey ( config ) <EOL> @ skipif ( '<STR_LIT>' not in sys . modules , '<STR_LIT>' ) <EOL> def test_pylearn2_autoencoder ( self ) : <EOL> config = """<STR_LIT>""" <EOL> self . run_osprey ( config ) <EOL> @ skipif ( '<STR_LIT>' not in sys . modules , '<STR_LIT>' ) <EOL> def test_pylearn2_dataset_loader ( self ) : <EOL> yaml_string = """<STR_LIT>""" <EOL> dataset_loader = Pylearn2DatasetLoader ( yaml_string , one_hot = False ) <EOL> X , y = dataset_loader . load ( ) <EOL> assert X . shape == ( <NUM_LIT:10> , <NUM_LIT:5> ) <EOL> assert y . shape == ( <NUM_LIT:10> , ) <EOL> assert np . unique ( y ) . size == <NUM_LIT:3> <EOL> @ skipif ( '<STR_LIT>' not in sys . modules , '<STR_LIT>' ) <EOL> def test_pylearn2_dataset_loader_one_hot ( self ) : <EOL> yaml_string = """<STR_LIT>""" <EOL> dataset_loader = Pylearn2DatasetLoader ( yaml_string , one_hot = True ) <EOL> X , y = dataset_loader . load ( ) <EOL> assert X . shape == ( <NUM_LIT:10> , <NUM_LIT:5> ) <EOL> assert y . shape == ( <NUM_LIT:10> , ) <EOL> assert np . unique ( y ) . size == <NUM_LIT:3> </s>
