<s> from __future__ import division <EOL> from vistrails . core . modules . vistrails_module import Module <EOL> from . . common import get_numpy <EOL> class Reshape ( Module ) : <EOL> """<STR_LIT>""" <EOL> _input_ports = [ <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) ] <EOL> _output_ports = [ <EOL> ( '<STR_LIT:value>' , '<STR_LIT>' ) ] <EOL> def compute ( self ) : <EOL> numpy = get_numpy ( ) <EOL> array = self . get_input ( '<STR_LIT>' ) <EOL> shape = self . get_input ( '<STR_LIT>' ) <EOL> array = numpy . array ( array ) . reshape ( shape ) <EOL> self . set_output ( '<STR_LIT:value>' , array ) <EOL> _modules = [ Reshape ] <EOL> import unittest <EOL> class ReshapeTestCase ( unittest . TestCase ) : <EOL> def test_reshape ( self ) : <EOL> """<STR_LIT>""" <EOL> from vistrails . tests . utils import execute , intercept_result <EOL> from . . identifiers import identifier <EOL> with intercept_result ( Reshape , '<STR_LIT:value>' ) as results : <EOL> self . assertFalse ( execute ( [ <EOL> ( '<STR_LIT>' , identifier , [ <EOL> ( '<STR_LIT>' , [ ( '<STR_LIT>' , '<STR_LIT>' ) ] ) , <EOL> ( '<STR_LIT>' , [ ( '<STR_LIT>' , '<STR_LIT>' ) ] ) , <EOL> ] ) , <EOL> ] ) ) <EOL> self . assertFalse ( execute ( [ <EOL> ( '<STR_LIT>' , identifier , [ <EOL> ( '<STR_LIT>' , [ ( '<STR_LIT>' , '<STR_LIT>' ) ] ) , <EOL> ( '<STR_LIT>' , [ ( '<STR_LIT>' , '<STR_LIT>' ) ] ) , <EOL> ] ) , <EOL> ] ) ) <EOL> self . assertEqual ( len ( results ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( results [ <NUM_LIT:0> ] . shape , ( <NUM_LIT:2> , <NUM_LIT:3> ) ) <EOL> self . assertTrue ( ( results [ <NUM_LIT:0> ] == [ [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> ] , [ <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> ] ] ) . all ( ) ) <EOL> self . assertEqual ( results [ <NUM_LIT:1> ] . shape , ( <NUM_LIT:6> , ) ) <EOL> self . assertTrue ( ( results [ <NUM_LIT:1> ] == [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> ] ) . all ( ) ) <EOL> def test_noreshape ( self ) : <EOL> """<STR_LIT>""" <EOL> from vistrails . tests . utils import execute <EOL> from . . identifiers import identifier <EOL> error = execute ( [ <EOL> ( '<STR_LIT>' , identifier , [ <EOL> ( '<STR_LIT>' , [ ( '<STR_LIT>' , '<STR_LIT>' ) ] ) , <EOL> ( '<STR_LIT>' , [ ( '<STR_LIT>' , '<STR_LIT>' ) ] ) , <EOL> ] ) , <EOL> ] ) <EOL> self . assertEqual ( error . keys ( ) , [ <NUM_LIT:0> ] ) <EOL> self . assertIn ( "<STR_LIT>" , <EOL> error [ <NUM_LIT:0> ] . args [ <NUM_LIT:0> ] ) </s>
