def test_string_truncation_warning():
 t = table.Table([['aa', 'bb']], names=['a'])
 with catch_warnings() as w:
  from inspect import currentframe, getframeinfo
  t['a'][1] = 'cc'
  assert (len(w) == 0)
  t['a'][:] = 'dd'
  assert (len(w) == 0)
 with catch_warnings() as w:
  frameinfo = getframeinfo(currentframe())
  t['a'][0] = 'eee'
  assert (t['a'][0] == 'ee')
  assert (len(w) == 1)
  assert ('truncated right side string(s) longer than 2 character(s)' in str(w[0].message))
  assert (w[0].lineno == (frameinfo.lineno + 1))
  assert (w[0].category is table.StringTruncateWarning)
  assert ('test_column' in w[0].filename)
 with catch_warnings() as w:
  t['a'][:] = ['ff', 'ggg']
  assert np.all((t['a'] == ['ff', 'gg']))
  assert (len(w) == 1)
  assert ('truncated right side string(s) longer than 2 character(s)' in str(w[0].message))

def test_string_truncation_warning ( ) : t = table . Table ( [ [ 'aa' , 'bb' ] ] , names = [ 'a' ] ) with catch_warnings ( ) as w : from inspect import currentframe , getframeinfo t [ 'a' ] [ 1 ] = 'cc' assert ( len ( w ) == 0 ) t [ 'a' ] [ : ] = 'dd' assert ( len ( w ) == 0 ) with catch_warnings ( ) as w : frameinfo = getframeinfo ( currentframe ( ) ) t [ 'a' ] [ 0 ] = 'eee' assert ( t [ 'a' ] [ 0 ] == 'ee' ) assert ( len ( w ) == 1 ) assert ( 'truncated right side string(s) longer than 2 character(s)' in str ( w [ 0 ] . message ) ) assert ( w [ 0 ] . lineno == ( frameinfo . lineno + 1 ) ) assert ( w [ 0 ] . category is table . StringTruncateWarning ) assert ( 'test_column' in w [ 0 ] . filename ) with catch_warnings ( ) as w : t [ 'a' ] [ : ] = [ 'ff' , 'ggg' ] assert np . all ( ( t [ 'a' ] == [ 'ff' , 'gg' ] ) ) assert ( len ( w ) == 1 ) assert ( 'truncated right side string(s) longer than 2 character(s)' in str ( w [ 0 ] . message ) )
test warnings associated with in-place assignment to a string column that results in truncation of the right hand side .