<s> from __future__ import absolute_import , division , print_function <EOL> import numpy as np <EOL> from numpy . testing import assert_array_equal <EOL> from glue . core import data_factories as df <EOL> def test_npy_load ( tmpdir ) : <EOL> data = np . array ( [ ( "<STR_LIT:a>" , <NUM_LIT> , - <NUM_LIT> ) , ( "<STR_LIT:b>" , <NUM_LIT> , <NUM_LIT> ) ] , <EOL> dtype = [ ( '<STR_LIT:name>' , '<STR_LIT>' ) , ( '<STR_LIT>' , '<STR_LIT>' ) , ( '<STR_LIT>' , '<STR_LIT>' ) ] ) <EOL> with open ( tmpdir . join ( '<STR_LIT>' ) . strpath , '<STR_LIT:wb>' ) as f : <EOL> np . save ( f , data ) <EOL> f . seek ( <NUM_LIT:0> ) <EOL> data2 = df . load_data ( f . name ) <EOL> assert_array_equal ( data [ '<STR_LIT:name>' ] , data2 . get_component ( '<STR_LIT:name>' ) . labels ) <EOL> assert_array_equal ( data [ '<STR_LIT>' ] , data2 [ '<STR_LIT>' ] ) <EOL> assert_array_equal ( data [ '<STR_LIT>' ] , data2 [ '<STR_LIT>' ] ) <EOL> def test_npz_load ( tmpdir ) : <EOL> data1 = np . array ( [ ( "<STR_LIT:a>" , <NUM_LIT> , - <NUM_LIT> ) , ( "<STR_LIT:b>" , <NUM_LIT> , <NUM_LIT> ) ] , <EOL> dtype = [ ( '<STR_LIT:name>' , '<STR_LIT>' ) , ( '<STR_LIT>' , '<STR_LIT>' ) , ( '<STR_LIT>' , '<STR_LIT>' ) ] ) <EOL> data2 = np . array ( [ ( "<STR_LIT:c>" , <NUM_LIT> , - <NUM_LIT> ) , ( "<STR_LIT:d>" , <NUM_LIT> , <NUM_LIT> ) ] , <EOL> dtype = [ ( '<STR_LIT:name>' , '<STR_LIT>' ) , ( '<STR_LIT:l>' , '<STR_LIT>' ) , ( '<STR_LIT:b>' , '<STR_LIT>' ) ] ) <EOL> with open ( tmpdir . join ( '<STR_LIT>' ) . strpath , '<STR_LIT:wb>' ) as f : <EOL> np . savez ( f , data1 = data1 , data2 = data2 ) <EOL> f . seek ( <NUM_LIT:0> ) <EOL> data_loaded = df . load_data ( f . name ) <EOL> arr = data_loaded [ <NUM_LIT:0> ] <EOL> assert_array_equal ( data1 [ '<STR_LIT:name>' ] , arr . get_component ( '<STR_LIT:name>' ) . labels ) <EOL> assert_array_equal ( data1 [ '<STR_LIT>' ] , arr [ '<STR_LIT>' ] ) <EOL> assert_array_equal ( data1 [ '<STR_LIT>' ] , arr [ '<STR_LIT>' ] ) <EOL> arr = data_loaded [ <NUM_LIT:1> ] <EOL> assert_array_equal ( data2 [ '<STR_LIT:name>' ] , arr . get_component ( '<STR_LIT:name>' ) . labels ) <EOL> assert_array_equal ( data2 [ '<STR_LIT:l>' ] , arr [ '<STR_LIT:l>' ] ) <EOL> assert_array_equal ( data2 [ '<STR_LIT:b>' ] , arr [ '<STR_LIT:b>' ] ) </s>
