<s> """<STR_LIT>""" <EOL> import os <EOL> import os . path as op <EOL> import subprocess <EOL> import numpy as np <EOL> from numpy . testing import assert_array_equal as ae <EOL> from pytest import raises <EOL> from six import string_types <EOL> from . . _misc import ( _git_version , _load_json , _save_json , _read_python , <EOL> _write_text , <EOL> _encode_qbytearray , _decode_qbytearray , <EOL> ) <EOL> def test_qbytearray ( tempdir ) : <EOL> from phy . gui . qt import QByteArray <EOL> arr = QByteArray ( ) <EOL> arr . append ( '<STR_LIT:1>' ) <EOL> arr . append ( '<STR_LIT:2>' ) <EOL> arr . append ( '<STR_LIT:3>' ) <EOL> encoded = _encode_qbytearray ( arr ) <EOL> assert isinstance ( encoded , string_types ) <EOL> decoded = _decode_qbytearray ( encoded ) <EOL> assert arr == decoded <EOL> d = { '<STR_LIT>' : arr } <EOL> path = op . join ( tempdir , '<STR_LIT:test>' ) <EOL> _save_json ( path , d ) <EOL> d_bis = _load_json ( path ) <EOL> assert d == d_bis <EOL> def test_json_simple ( tempdir ) : <EOL> d = { '<STR_LIT:a>' : <NUM_LIT:1> , '<STR_LIT:b>' : '<STR_LIT>' , <NUM_LIT:3> : '<STR_LIT>' , '<STR_LIT>' : { '<STR_LIT>' : True } } <EOL> path = op . join ( tempdir , '<STR_LIT:test>' ) <EOL> _save_json ( path , d ) <EOL> d_bis = _load_json ( path ) <EOL> assert d == d_bis <EOL> with open ( path , '<STR_LIT:w>' ) as f : <EOL> f . write ( '<STR_LIT>' ) <EOL> assert _load_json ( path ) == { } <EOL> with raises ( IOError ) : <EOL> _load_json ( path + '<STR_LIT>' ) <EOL> def test_json_numpy ( tempdir ) : <EOL> arr = np . arange ( <NUM_LIT:10> ) . reshape ( ( <NUM_LIT:2> , <NUM_LIT:5> ) ) . astype ( np . float32 ) <EOL> d = { '<STR_LIT:a>' : arr , '<STR_LIT:b>' : arr . ravel ( ) [ <NUM_LIT:0> ] } <EOL> path = op . join ( tempdir , '<STR_LIT:test>' ) <EOL> _save_json ( path , d ) <EOL> d_bis = _load_json ( path ) <EOL> arr_bis = d_bis [ '<STR_LIT:a>' ] <EOL> assert arr_bis . dtype == arr . dtype <EOL> assert arr_bis . shape == arr . shape <EOL> ae ( arr_bis , arr ) <EOL> assert d [ '<STR_LIT:b>' ] == d_bis [ '<STR_LIT:b>' ] <EOL> def test_read_python ( tempdir ) : <EOL> path = op . join ( tempdir , '<STR_LIT>' ) <EOL> with open ( path , '<STR_LIT:w>' ) as f : <EOL> f . write ( """<STR_LIT>""" ) <EOL> assert _read_python ( path ) == { '<STR_LIT:a>' : { '<STR_LIT:b>' : <NUM_LIT:1> } } <EOL> def test_write_text ( tempdir ) : <EOL> for path in ( op . join ( tempdir , '<STR_LIT>' ) , <EOL> op . join ( tempdir , '<STR_LIT>' ) , <EOL> ) : <EOL> _write_text ( path , '<STR_LIT>' ) <EOL> with open ( path , '<STR_LIT:r>' ) as f : <EOL> assert f . read ( ) == '<STR_LIT>' <EOL> def test_git_version ( ) : <EOL> v = _git_version ( ) <EOL> filedir , _ = op . split ( __file__ ) <EOL> try : <EOL> fnull = open ( os . devnull , '<STR_LIT:w>' ) <EOL> subprocess . check_output ( [ '<STR_LIT>' , '<STR_LIT>' , filedir , '<STR_LIT:status>' ] , <EOL> stderr = fnull ) <EOL> assert v is not "<STR_LIT>" , "<STR_LIT>" <EOL> assert v [ : <NUM_LIT:5> ] == "<STR_LIT>" , "<STR_LIT>" <EOL> except ( OSError , subprocess . CalledProcessError ) : <EOL> assert v == "<STR_LIT>" </s>
