def test_precision():
 f = PlainTextFormatter()
 nt.assert_equal(f(pi), repr(pi))
 f.float_precision = 0
 if numpy:
  po = numpy.get_printoptions()
  nt.assert_equal(po['precision'], 0)
 nt.assert_equal(f(pi), '3')
 f.float_precision = 2
 if numpy:
  po = numpy.get_printoptions()
  nt.assert_equal(po['precision'], 2)
 nt.assert_equal(f(pi), '3.14')
 f.float_precision = '%g'
 if numpy:
  po = numpy.get_printoptions()
  nt.assert_equal(po['precision'], 2)
 nt.assert_equal(f(pi), '3.14159')
 f.float_precision = '%e'
 nt.assert_equal(f(pi), '3.141593e+00')
 f.float_precision = ''
 if numpy:
  po = numpy.get_printoptions()
  nt.assert_equal(po['precision'], 8)
 nt.assert_equal(f(pi), repr(pi))

def test_precision ( ) : f = PlainTextFormatter ( ) nt . assert_equal ( f ( pi ) , repr ( pi ) ) f . float_precision = 0 if numpy : po = numpy . get_printoptions ( ) nt . assert_equal ( po [ 'precision' ] , 0 ) nt . assert_equal ( f ( pi ) , '3' ) f . float_precision = 2 if numpy : po = numpy . get_printoptions ( ) nt . assert_equal ( po [ 'precision' ] , 2 ) nt . assert_equal ( f ( pi ) , '3.14' ) f . float_precision = '%g' if numpy : po = numpy . get_printoptions ( ) nt . assert_equal ( po [ 'precision' ] , 2 ) nt . assert_equal ( f ( pi ) , '3.14159' ) f . float_precision = '%e' nt . assert_equal ( f ( pi ) , '3.141593e+00' ) f . float_precision = '' if numpy : po = numpy . get_printoptions ( ) nt . assert_equal ( po [ 'precision' ] , 8 ) nt . assert_equal ( f ( pi ) , repr ( pi ) )
test various values for float_precision .