<s> import numpy as np <EOL> import pyfits as fits <EOL> from . . extern . six import StringIO <EOL> from . . column import Column <EOL> from . . diff import ( FITSDiff , HeaderDiff , ImageDataDiff , TableDataDiff , <EOL> report_diff_values ) <EOL> from . . hdu import HDUList , PrimaryHDU , ImageHDU <EOL> from . . hdu . table import BinTableHDU <EOL> from . . header import Header <EOL> from . import PyfitsTestCase <EOL> from nose . tools import assert_raises <EOL> class TestDiff ( PyfitsTestCase ) : <EOL> def test_identical_headers ( self ) : <EOL> ha = Header ( [ ( '<STR_LIT:A>' , <NUM_LIT:1> ) , ( '<STR_LIT:B>' , <NUM_LIT:2> ) , ( '<STR_LIT:C>' , <NUM_LIT:3> ) ] ) <EOL> hb = ha . copy ( ) <EOL> assert HeaderDiff ( ha , hb ) . identical <EOL> def test_slightly_different_headers ( self ) : <EOL> ha = Header ( [ ( '<STR_LIT:A>' , <NUM_LIT:1> ) , ( '<STR_LIT:B>' , <NUM_LIT:2> ) , ( '<STR_LIT:C>' , <NUM_LIT:3> ) ] ) <EOL> hb = ha . copy ( ) <EOL> hb [ '<STR_LIT:C>' ] = <NUM_LIT:4> <EOL> assert not HeaderDiff ( ha , hb ) . identical <EOL> def test_common_keywords ( self ) : <EOL> ha = Header ( [ ( '<STR_LIT:A>' , <NUM_LIT:1> ) , ( '<STR_LIT:B>' , <NUM_LIT:2> ) , ( '<STR_LIT:C>' , <NUM_LIT:3> ) ] ) <EOL> hb = ha . copy ( ) <EOL> hb [ '<STR_LIT:C>' ] = <NUM_LIT:4> <EOL> hb [ '<STR_LIT:D>' ] = ( <NUM_LIT:5> , '<STR_LIT>' ) <EOL> assert HeaderDiff ( ha , hb ) . common_keywords == [ '<STR_LIT:A>' , '<STR_LIT:B>' , '<STR_LIT:C>' ] <EOL> def test_different_keyword_count ( self ) : <EOL> ha = Header ( [ ( '<STR_LIT:A>' , <NUM_LIT:1> ) , ( '<STR_LIT:B>' , <NUM_LIT:2> ) , ( '<STR_LIT:C>' , <NUM_LIT:3> ) ] ) <EOL> hb = ha . copy ( ) <EOL> del hb [ '<STR_LIT:B>' ] <EOL> diff = HeaderDiff ( ha , hb ) <EOL> assert not diff . identical <EOL> assert diff . diff_keyword_count == ( <NUM_LIT:3> , <NUM_LIT:2> ) <EOL> assert diff . common_keywords == [ '<STR_LIT:A>' , '<STR_LIT:C>' ] <EOL> def test_different_keywords ( self ) : <EOL> ha = Header ( [ ( '<STR_LIT:A>' , <NUM_LIT:1> ) , ( '<STR_LIT:B>' , <NUM_LIT:2> ) , ( '<STR_LIT:C>' , <NUM_LIT:3> ) ] ) <EOL> hb = ha . copy ( ) <EOL> hb [ '<STR_LIT:C>' ] = <NUM_LIT:4> <EOL> hb [ '<STR_LIT:D>' ] = ( <NUM_LIT:5> , '<STR_LIT>' ) <EOL> ha [ '<STR_LIT:E>' ] = ( <NUM_LIT:6> , '<STR_LIT>' ) <EOL> ha [ '<STR_LIT:F>' ] = ( <NUM_LIT:7> , '<STR_LIT>' ) <EOL> diff = HeaderDiff ( ha , hb ) <EOL> assert not diff . identical <EOL> assert diff . diff_keywords == ( [ '<STR_LIT:E>' , '<STR_LIT:F>' ] , [ '<STR_LIT:D>' ] ) <EOL> def test_different_keyword_values ( self ) : <EOL> ha = Header ( [ ( '<STR_LIT:A>' , <NUM_LIT:1> ) , ( '<STR_LIT:B>' , <NUM_LIT:2> ) , ( '<STR_LIT:C>' , <NUM_LIT:3> ) ] ) <EOL> hb = ha . copy ( ) <EOL> hb [ '<STR_LIT:C>' ] = <NUM_LIT:4> <EOL> diff = HeaderDiff ( ha , hb ) <EOL> assert not diff . identical <EOL> assert diff . diff_keyword_values == { '<STR_LIT:C>' : [ ( <NUM_LIT:3> , <NUM_LIT:4> ) ] } <EOL> def test_different_keyword_comments ( self ) : <EOL> ha = Header ( [ ( '<STR_LIT:A>' , <NUM_LIT:1> ) , ( '<STR_LIT:B>' , <NUM_LIT:2> ) , ( '<STR_LIT:C>' , <NUM_LIT:3> , '<STR_LIT>' ) ] ) <EOL> hb = ha . copy ( ) <EOL> hb . comments [ '<STR_LIT:C>' ] = '<STR_LIT>' <EOL> diff = HeaderDiff ( ha , hb ) <EOL> assert not diff . identical <EOL> assert ( diff . diff_keyword_comments == <EOL> { '<STR_LIT:C>' : [ ( '<STR_LIT>' , '<STR_LIT>' ) ] } ) <EOL> def test_different_keyword_values_with_duplicate ( self ) : <EOL> ha = Header ( [ ( '<STR_LIT:A>' , <NUM_LIT:1> ) , ( '<STR_LIT:B>' , <NUM_LIT:2> ) , ( '<STR_LIT:C>' , <NUM_LIT:3> ) ] ) <EOL> hb = ha . copy ( ) <EOL> ha . append ( ( '<STR_LIT:C>' , <NUM_LIT:4> ) ) <EOL> hb . append ( ( '<STR_LIT:C>' , <NUM_LIT:5> ) ) <EOL> diff = HeaderDiff ( ha , hb ) <EOL> assert not diff . identical <EOL> assert diff . diff_keyword_values == { '<STR_LIT:C>' : [ None , ( <NUM_LIT:4> , <NUM_LIT:5> ) ] } <EOL> def test_asymmetric_duplicate_keywords ( self ) : <EOL> ha = Header ( [ ( '<STR_LIT:A>' , <NUM_LIT:1> ) , ( '<STR_LIT:B>' , <NUM_LIT:2> ) , ( '<STR_LIT:C>' , <NUM_LIT:3> ) ] ) <EOL> hb = ha . copy ( ) <EOL> ha . append ( ( '<STR_LIT:A>' , <NUM_LIT:2> , '<STR_LIT>' ) ) <EOL> ha . append ( ( '<STR_LIT:A>' , <NUM_LIT:3> , '<STR_LIT>' ) ) <EOL> hb . append ( ( '<STR_LIT:B>' , <NUM_LIT:4> , '<STR_LIT>' ) ) <EOL> hb . append ( ( '<STR_LIT:C>' , <NUM_LIT:5> , '<STR_LIT>' ) ) <EOL> diff = HeaderDiff ( ha , hb ) <EOL> assert not diff . identical <EOL> assert diff . diff_keyword_values == { } <EOL> assert ( diff . diff_duplicate_keywords == <EOL> { '<STR_LIT:A>' : ( <NUM_LIT:3> , <NUM_LIT:1> ) , '<STR_LIT:B>' : ( <NUM_LIT:1> , <NUM_LIT:2> ) , '<STR_LIT:C>' : ( <NUM_LIT:1> , <NUM_LIT:2> ) } ) <EOL> def test_floating_point_tolerance ( self ) : <EOL> ha = Header ( [ ( '<STR_LIT:A>' , <NUM_LIT:1> ) , ( '<STR_LIT:B>' , <NUM_LIT> ) , ( '<STR_LIT:C>' , <NUM_LIT> ) ] ) <EOL> hb = ha . copy ( ) <EOL> hb [ '<STR_LIT:B>' ] = <NUM_LIT> <EOL> hb [ '<STR_LIT:C>' ] = <NUM_LIT> <EOL> diff = HeaderDiff ( ha , hb ) <EOL> assert not diff . identical <EOL> assert ( diff . diff_keyword_values == <EOL> { '<STR_LIT:B>' : [ ( <NUM_LIT> , <NUM_LIT> ) ] , '<STR_LIT:C>' : [ ( <NUM_LIT> , <NUM_LIT> ) ] } ) <EOL> diff = HeaderDiff ( ha , hb , tolerance = <NUM_LIT> ) <EOL> assert not diff . identical <EOL> assert diff . diff_keyword_values == { '<STR_LIT:B>' : [ ( <NUM_LIT> , <NUM_LIT> ) ] } <EOL> def test_ignore_blanks ( self ) : <EOL> fits . STRIP_HEADER_WHITESPACE = False <EOL> try : <EOL> ha = Header ( [ ( '<STR_LIT:A>' , <NUM_LIT:1> ) , ( '<STR_LIT:B>' , <NUM_LIT:2> ) , ( '<STR_LIT:C>' , '<STR_LIT>' ) ] ) <EOL> hb = ha . copy ( ) <EOL> hb [ '<STR_LIT:C>' ] = '<STR_LIT:A>' <EOL> assert ha [ '<STR_LIT:C>' ] != hb [ '<STR_LIT:C>' ] <EOL> diff = HeaderDiff ( ha , hb ) <EOL> assert diff . identical <EOL> assert diff . diff_keyword_values == { } <EOL> diff = HeaderDiff ( ha , hb , ignore_blanks = False ) <EOL> assert not diff . identical <EOL> assert diff . diff_keyword_values == { '<STR_LIT:C>' : [ ( '<STR_LIT>' , '<STR_LIT:A>' ) ] } <EOL> finally : <EOL> fits . STRIP_HEADER_WHITESPACE = True <EOL> def test_ignore_blank_cards ( self ) : <EOL> """<STR_LIT>""" <EOL> ha = Header ( [ ( '<STR_LIT:A>' , <NUM_LIT:1> ) , ( '<STR_LIT:B>' , <NUM_LIT:2> ) , ( '<STR_LIT:C>' , <NUM_LIT:3> ) ] ) <EOL> hb = Header ( [ ( '<STR_LIT:A>' , <NUM_LIT:1> ) , ( '<STR_LIT>' , '<STR_LIT>' ) , ( '<STR_LIT:B>' , <NUM_LIT:2> ) , ( '<STR_LIT>' , '<STR_LIT>' ) , ( '<STR_LIT:C>' , <NUM_LIT:3> ) ] ) <EOL> hc = ha . copy ( ) <EOL> hc . append ( ) <EOL> hc . append ( ) <EOL> assert HeaderDiff ( ha , hb ) . identical <EOL> assert HeaderDiff ( ha , hc ) . identical <EOL> assert HeaderDiff ( hb , hc ) . identical <EOL> assert not HeaderDiff ( ha , hb , ignore_blank_cards = False ) . identical <EOL> assert not HeaderDiff ( ha , hc , ignore_blank_cards = False ) . identical <EOL> assert HeaderDiff ( hb , hc , ignore_blank_cards = False ) . identical <EOL> hc . append ( ) <EOL> assert not HeaderDiff ( hb , hc , ignore_blank_cards = False ) . identical <EOL> def test_ignore_keyword_values ( self ) : <EOL> ha = Header ( [ ( '<STR_LIT:A>' , <NUM_LIT:1> ) , ( '<STR_LIT:B>' , <NUM_LIT:2> ) , ( '<STR_LIT:C>' , <NUM_LIT:3> ) ] ) <EOL> hb = ha . copy ( ) <EOL> hb [ '<STR_LIT:B>' ] = <NUM_LIT:4> <EOL> hb [ '<STR_LIT:C>' ] = <NUM_LIT:5> <EOL> diff = HeaderDiff ( ha , hb , ignore_keywords = [ '<STR_LIT:*>' ] ) <EOL> assert diff . identical <EOL> diff = HeaderDiff ( ha , hb , ignore_keywords = [ '<STR_LIT:B>' ] ) <EOL> assert not diff . identical <EOL> assert diff . diff_keyword_values == { '<STR_LIT:C>' : [ ( <NUM_LIT:3> , <NUM_LIT:5> ) ] } <EOL> report = diff . report ( ) <EOL> assert '<STR_LIT>' not in report <EOL> assert '<STR_LIT>' in report <EOL> diff = HeaderDiff ( ha , hb , ignore_keywords = [ '<STR_LIT:b>' ] ) <EOL> assert not diff . identical <EOL> assert diff . diff_keyword_values == { '<STR_LIT:C>' : [ ( <NUM_LIT:3> , <NUM_LIT:5> ) ] } <EOL> def test_ignore_keyword_comments ( self ) : <EOL> ha = Header ( [ ( '<STR_LIT:A>' , <NUM_LIT:1> , '<STR_LIT:A>' ) , ( '<STR_LIT:B>' , <NUM_LIT:2> , '<STR_LIT:B>' ) , ( '<STR_LIT:C>' , <NUM_LIT:3> , '<STR_LIT:C>' ) ] ) <EOL> hb = ha . copy ( ) <EOL> hb . comments [ '<STR_LIT:B>' ] = '<STR_LIT:D>' <EOL> hb . comments [ '<STR_LIT:C>' ] = '<STR_LIT:E>' <EOL> diff = HeaderDiff ( ha , hb , ignore_comments = [ '<STR_LIT:*>' ] ) <EOL> assert diff . identical <EOL> diff = HeaderDiff ( ha , hb , ignore_comments = [ '<STR_LIT:B>' ] ) <EOL> assert not diff . identical <EOL> assert diff . diff_keyword_comments == { '<STR_LIT:C>' : [ ( '<STR_LIT:C>' , '<STR_LIT:E>' ) ] } <EOL> report = diff . report ( ) <EOL> assert '<STR_LIT>' not in report <EOL> assert '<STR_LIT>' in report <EOL> diff = HeaderDiff ( ha , hb , ignore_comments = [ '<STR_LIT:b>' ] ) <EOL> assert not diff . identical <EOL> assert diff . diff_keyword_comments == { '<STR_LIT:C>' : [ ( '<STR_LIT:C>' , '<STR_LIT:E>' ) ] } <EOL> def test_trivial_identical_images ( self ) : <EOL> ia = np . arange ( <NUM_LIT:100> ) . reshape ( ( <NUM_LIT:10> , <NUM_LIT:10> ) ) <EOL> ib = np . arange ( <NUM_LIT:100> ) . reshape ( ( <NUM_LIT:10> , <NUM_LIT:10> ) ) <EOL> diff = ImageDataDiff ( ia , ib ) <EOL> assert diff . identical <EOL> assert diff . diff_total == <NUM_LIT:0> <EOL> def test_identical_within_tolerance ( self ) : <EOL> ia = np . ones ( ( <NUM_LIT:10> , <NUM_LIT:10> ) ) - <NUM_LIT> <EOL> ib = np . ones ( ( <NUM_LIT:10> , <NUM_LIT:10> ) ) - <NUM_LIT> <EOL> diff = ImageDataDiff ( ia , ib , tolerance = <NUM_LIT> ) <EOL> assert diff . identical <EOL> assert diff . diff_total == <NUM_LIT:0> <EOL> def test_identical_comp_image_hdus ( self ) : <EOL> """<STR_LIT>""" <EOL> data = np . arange ( <NUM_LIT> ) . reshape ( ( <NUM_LIT:10> , <NUM_LIT:10> ) ) <EOL> hdu = fits . CompImageHDU ( data = data ) <EOL> hdu . writeto ( self . temp ( '<STR_LIT>' ) ) <EOL> hdula = fits . open ( self . temp ( '<STR_LIT>' ) ) <EOL> hdulb = fits . open ( self . temp ( '<STR_LIT>' ) ) <EOL> diff = FITSDiff ( hdula , hdulb ) <EOL> assert diff . identical <EOL> def test_different_dimensions ( self ) : <EOL> ia = np . arange ( <NUM_LIT:100> ) . reshape ( ( <NUM_LIT:10> , <NUM_LIT:10> ) ) <EOL> ib = np . arange ( <NUM_LIT:100> ) - <NUM_LIT:1> <EOL> diff = ImageDataDiff ( ia , ib ) <EOL> assert not diff . identical <EOL> assert diff . diff_dimensions == ( ( <NUM_LIT:10> , <NUM_LIT:10> ) , ( <NUM_LIT:100> , ) ) <EOL> assert diff . diff_total == <NUM_LIT:0> <EOL> report = diff . report ( ) <EOL> assert '<STR_LIT>' in report <EOL> assert '<STR_LIT>' in report <EOL> assert '<STR_LIT>' in report <EOL> assert '<STR_LIT>' <EOL> def test_different_pixels ( self ) : <EOL> ia = np . arange ( <NUM_LIT:100> ) . reshape ( ( <NUM_LIT:10> , <NUM_LIT:10> ) ) <EOL> ib = np . arange ( <NUM_LIT:100> ) . reshape ( ( <NUM_LIT:10> , <NUM_LIT:10> ) ) <EOL> ib [ <NUM_LIT:0> , <NUM_LIT:0> ] = <NUM_LIT:10> <EOL> ib [ <NUM_LIT:5> , <NUM_LIT:5> ] = <NUM_LIT:20> <EOL> diff = ImageDataDiff ( ia , ib ) <EOL> assert not diff . identical <EOL> assert diff . diff_dimensions == ( ) <EOL> assert diff . diff_total == <NUM_LIT:2> <EOL> assert diff . diff_ratio == <NUM_LIT> <EOL> assert diff . diff_pixels == [ ( ( <NUM_LIT:0> , <NUM_LIT:0> ) , ( <NUM_LIT:0> , <NUM_LIT:10> ) ) , ( ( <NUM_LIT:5> , <NUM_LIT:5> ) , ( <NUM_LIT> , <NUM_LIT:20> ) ) ] <EOL> def test_identical_tables ( self ) : <EOL> c1 = Column ( '<STR_LIT:A>' , format = '<STR_LIT:L>' , array = [ True , False ] ) <EOL> c2 = Column ( '<STR_LIT:B>' , format = '<STR_LIT:X>' , array = [ [ <NUM_LIT:0> ] , [ <NUM_LIT:1> ] ] ) <EOL> c3 = Column ( '<STR_LIT:C>' , format = '<STR_LIT>' , dim = '<STR_LIT>' , <EOL> array = [ [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] , [ <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:7> ] ] ) <EOL> c4 = Column ( '<STR_LIT:D>' , format = '<STR_LIT>' , bscale = <NUM_LIT> , array = [ <NUM_LIT:0> , <NUM_LIT:1> ] ) <EOL> c5 = Column ( '<STR_LIT:E>' , format = '<STR_LIT>' , array = [ '<STR_LIT:abc>' , '<STR_LIT>' ] ) <EOL> c6 = Column ( '<STR_LIT:F>' , format = '<STR_LIT:E>' , unit = '<STR_LIT:m>' , array = [ <NUM_LIT:0.0> , <NUM_LIT:1.0> ] ) <EOL> c7 = Column ( '<STR_LIT>' , format = '<STR_LIT:D>' , bzero = - <NUM_LIT:0.1> , array = [ <NUM_LIT:0.0> , <NUM_LIT:1.0> ] ) <EOL> c8 = Column ( '<STR_LIT:H>' , format = '<STR_LIT:C>' , array = [ <NUM_LIT:0.0> + <NUM_LIT> , <NUM_LIT> + <NUM_LIT> ] ) <EOL> c9 = Column ( '<STR_LIT:I>' , format = '<STR_LIT:M>' , array = [ <NUM_LIT> + <NUM_LIT> , <NUM_LIT> + <NUM_LIT> ] ) <EOL> c10 = Column ( '<STR_LIT>' , format = '<STR_LIT>' , array = [ [ <NUM_LIT:0> , <NUM_LIT:1> ] , [ <NUM_LIT:2> , <NUM_LIT:3> ] ] ) <EOL> columns = [ c1 , c2 , c3 , c4 , c5 , c6 , c7 , c8 , c9 , c10 ] <EOL> ta = BinTableHDU . from_columns ( columns ) <EOL> tb = BinTableHDU . from_columns ( [ c . copy ( ) for c in columns ] ) <EOL> diff = TableDataDiff ( ta . data , tb . data ) <EOL> assert diff . identical <EOL> assert len ( diff . common_columns ) == <NUM_LIT:10> <EOL> assert ( diff . common_column_names == <EOL> set ( [ '<STR_LIT:a>' , '<STR_LIT:b>' , '<STR_LIT:c>' , '<STR_LIT:d>' , '<STR_LIT:e>' , '<STR_LIT:f>' , '<STR_LIT:g>' , '<STR_LIT:h>' , '<STR_LIT:i>' , '<STR_LIT>' ] ) ) <EOL> assert diff . diff_ratio == <NUM_LIT:0> <EOL> assert diff . diff_total == <NUM_LIT:0> <EOL> def test_diff_empty_tables ( self ) : <EOL> """<STR_LIT>""" <EOL> c1 = Column ( '<STR_LIT:D>' , format = '<STR_LIT>' ) <EOL> c2 = Column ( '<STR_LIT:E>' , format = '<STR_LIT>' ) <EOL> thdu = BinTableHDU . from_columns ( [ c1 , c2 ] , nrows = <NUM_LIT:0> ) <EOL> hdula = fits . HDUList ( [ thdu ] ) <EOL> hdulb = fits . HDUList ( [ thdu ] ) <EOL> diff = FITSDiff ( hdula , hdulb ) <EOL> assert diff . identical <EOL> def test_ignore_table_fields ( self ) : <EOL> c1 = Column ( '<STR_LIT:A>' , format = '<STR_LIT:L>' , array = [ True , False ] ) <EOL> c2 = Column ( '<STR_LIT:B>' , format = '<STR_LIT:X>' , array = [ [ <NUM_LIT:0> ] , [ <NUM_LIT:1> ] ] ) <EOL> c3 = Column ( '<STR_LIT:C>' , format = '<STR_LIT>' , dim = '<STR_LIT>' , <EOL> array = [ [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] , [ <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:7> ] ] ) <EOL> c4 = Column ( '<STR_LIT:B>' , format = '<STR_LIT:X>' , array = [ [ <NUM_LIT:1> ] , [ <NUM_LIT:0> ] ] ) <EOL> c5 = Column ( '<STR_LIT:C>' , format = '<STR_LIT>' , dim = '<STR_LIT>' , <EOL> array = [ [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> ] , [ <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:7> , <NUM_LIT:8> ] ] ) <EOL> ta = BinTableHDU . from_columns ( [ c1 , c2 , c3 ] ) <EOL> tb = BinTableHDU . from_columns ( [ c1 , c4 , c5 ] ) <EOL> diff = TableDataDiff ( ta . data , tb . data , ignore_fields = [ '<STR_LIT:B>' , '<STR_LIT:C>' ] ) <EOL> assert diff . identical <EOL> assert len ( diff . common_columns ) == <NUM_LIT:1> <EOL> assert diff . common_column_names == set ( [ '<STR_LIT:a>' ] ) <EOL> assert diff . diff_ratio == <NUM_LIT:0> <EOL> assert diff . diff_total == <NUM_LIT:0> <EOL> def test_different_table_field_names ( self ) : <EOL> ca = Column ( '<STR_LIT:A>' , format = '<STR_LIT:L>' , array = [ True , False ] ) <EOL> cb = Column ( '<STR_LIT:B>' , format = '<STR_LIT:L>' , array = [ True , False ] ) <EOL> cc = Column ( '<STR_LIT:C>' , format = '<STR_LIT:L>' , array = [ True , False ] ) <EOL> ta = BinTableHDU . from_columns ( [ ca , cb ] ) <EOL> tb = BinTableHDU . from_columns ( [ ca , cc ] ) <EOL> diff = TableDataDiff ( ta . data , tb . data ) <EOL> assert not diff . identical <EOL> assert len ( diff . common_columns ) == <NUM_LIT:1> <EOL> assert diff . common_column_names == set ( [ '<STR_LIT:a>' ] ) <EOL> assert diff . diff_column_names == ( [ '<STR_LIT:B>' ] , [ '<STR_LIT:C>' ] ) <EOL> assert diff . diff_ratio == <NUM_LIT:0> <EOL> assert diff . diff_total == <NUM_LIT:0> <EOL> def test_different_table_field_counts ( self ) : <EOL> """<STR_LIT>""" <EOL> ca = Column ( '<STR_LIT:A>' , format = '<STR_LIT:L>' , array = [ True , False ] ) <EOL> cb = Column ( '<STR_LIT:B>' , format = '<STR_LIT:L>' , array = [ True , False ] ) <EOL> cc = Column ( '<STR_LIT:C>' , format = '<STR_LIT:L>' , array = [ True , False ] ) <EOL> ta = BinTableHDU . from_columns ( [ cb ] ) <EOL> tb = BinTableHDU . from_columns ( [ ca , cb , cc ] ) <EOL> diff = TableDataDiff ( ta . data , tb . data ) <EOL> assert not diff . identical <EOL> assert diff . diff_column_count == ( <NUM_LIT:1> , <NUM_LIT:3> ) <EOL> assert len ( diff . common_columns ) == <NUM_LIT:1> <EOL> assert diff . common_column_names == set ( [ '<STR_LIT:b>' ] ) <EOL> assert diff . diff_column_names == ( [ ] , [ '<STR_LIT:A>' , '<STR_LIT:C>' ] ) <EOL> assert diff . diff_ratio == <NUM_LIT:0> <EOL> assert diff . diff_total == <NUM_LIT:0> <EOL> def test_different_table_rows ( self ) : <EOL> """<STR_LIT>""" <EOL> ca1 = Column ( '<STR_LIT:A>' , format = '<STR_LIT:L>' , array = [ True , False ] ) <EOL> cb1 = Column ( '<STR_LIT:B>' , format = '<STR_LIT:L>' , array = [ True , False ] ) <EOL> ca2 = Column ( '<STR_LIT:A>' , format = '<STR_LIT:L>' , array = [ True , False , True ] ) <EOL> cb2 = Column ( '<STR_LIT:B>' , format = '<STR_LIT:L>' , array = [ True , False , True ] ) <EOL> ta = BinTableHDU . from_columns ( [ ca1 , cb1 ] ) <EOL> tb = BinTableHDU . from_columns ( [ ca2 , cb2 ] ) <EOL> diff = TableDataDiff ( ta . data , tb . data ) <EOL> assert not diff . identical <EOL> assert diff . diff_column_count == ( ) <EOL> assert len ( diff . common_columns ) == <NUM_LIT:2> <EOL> assert diff . diff_rows == ( <NUM_LIT:2> , <NUM_LIT:3> ) <EOL> assert diff . diff_values == [ ] <EOL> report = diff . report ( ) <EOL> assert '<STR_LIT>' in report <EOL> assert '<STR_LIT>' in report <EOL> assert '<STR_LIT>' in report <EOL> assert '<STR_LIT>' <EOL> def test_different_table_data ( self ) : <EOL> """<STR_LIT>""" <EOL> ca1 = Column ( '<STR_LIT:A>' , format = '<STR_LIT:L>' , array = [ True , False ] ) <EOL> ca2 = Column ( '<STR_LIT:B>' , format = '<STR_LIT:X>' , array = [ [ <NUM_LIT:0> ] , [ <NUM_LIT:1> ] ] ) <EOL> ca3 = Column ( '<STR_LIT:C>' , format = '<STR_LIT>' , dim = '<STR_LIT>' , <EOL> array = [ [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] , [ <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:7> ] ] ) <EOL> ca4 = Column ( '<STR_LIT:D>' , format = '<STR_LIT>' , bscale = <NUM_LIT> , array = [ <NUM_LIT:0.0> , <NUM_LIT> ] ) <EOL> ca5 = Column ( '<STR_LIT:E>' , format = '<STR_LIT>' , array = [ '<STR_LIT:abc>' , '<STR_LIT>' ] ) <EOL> ca6 = Column ( '<STR_LIT:F>' , format = '<STR_LIT:E>' , unit = '<STR_LIT:m>' , array = [ <NUM_LIT:0.0> , <NUM_LIT:1.0> ] ) <EOL> ca7 = Column ( '<STR_LIT>' , format = '<STR_LIT:D>' , bzero = - <NUM_LIT:0.1> , array = [ <NUM_LIT:0.0> , <NUM_LIT:1.0> ] ) <EOL> ca8 = Column ( '<STR_LIT:H>' , format = '<STR_LIT:C>' , array = [ <NUM_LIT:0.0> + <NUM_LIT> , <NUM_LIT> + <NUM_LIT> ] ) <EOL> ca9 = Column ( '<STR_LIT:I>' , format = '<STR_LIT:M>' , array = [ <NUM_LIT> + <NUM_LIT> , <NUM_LIT> + <NUM_LIT> ] ) <EOL> ca10 = Column ( '<STR_LIT>' , format = '<STR_LIT>' , array = [ [ <NUM_LIT:0> , <NUM_LIT:1> ] , [ <NUM_LIT:2> , <NUM_LIT:3> ] ] ) <EOL> cb1 = Column ( '<STR_LIT:A>' , format = '<STR_LIT:L>' , array = [ False , False ] ) <EOL> cb2 = Column ( '<STR_LIT:B>' , format = '<STR_LIT:X>' , array = [ [ <NUM_LIT:0> ] , [ <NUM_LIT:0> ] ] ) <EOL> cb3 = Column ( '<STR_LIT:C>' , format = '<STR_LIT>' , dim = '<STR_LIT>' , <EOL> array = [ [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] , [ <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:7> , <NUM_LIT:8> ] ] ) <EOL> cb4 = Column ( '<STR_LIT:D>' , format = '<STR_LIT>' , bscale = <NUM_LIT> , array = [ <NUM_LIT> , <NUM_LIT> ] ) <EOL> cb5 = Column ( '<STR_LIT:E>' , format = '<STR_LIT>' , array = [ '<STR_LIT:abc>' , '<STR_LIT>' ] ) <EOL> cb6 = Column ( '<STR_LIT:F>' , format = '<STR_LIT:E>' , unit = '<STR_LIT:m>' , array = [ <NUM_LIT:1.0> , <NUM_LIT> ] ) <EOL> cb7 = Column ( '<STR_LIT>' , format = '<STR_LIT:D>' , bzero = - <NUM_LIT:0.1> , array = [ <NUM_LIT> , <NUM_LIT> ] ) <EOL> cb8 = Column ( '<STR_LIT:H>' , format = '<STR_LIT:C>' , array = [ <NUM_LIT:1.0> + <NUM_LIT> , <NUM_LIT> + <NUM_LIT> ] ) <EOL> cb9 = Column ( '<STR_LIT:I>' , format = '<STR_LIT:M>' , array = [ <NUM_LIT> + <NUM_LIT> , <NUM_LIT> + <NUM_LIT> ] ) <EOL> cb10 = Column ( '<STR_LIT>' , format = '<STR_LIT>' , array = [ [ <NUM_LIT:1> , <NUM_LIT:2> ] , [ <NUM_LIT:3> , <NUM_LIT:4> ] ] ) <EOL> ta = BinTableHDU . from_columns ( [ ca1 , ca2 , ca3 , ca4 , ca5 , ca6 , ca7 , <EOL> ca8 , ca9 , ca10 ] ) <EOL> tb = BinTableHDU . from_columns ( [ cb1 , cb2 , cb3 , cb4 , cb5 , cb6 , cb7 , <EOL> cb8 , cb9 , cb10 ] ) <EOL> diff = TableDataDiff ( ta . data , tb . data , numdiffs = <NUM_LIT:20> ) <EOL> assert not diff . identical <EOL> assert diff . diff_columns == ( ) <EOL> assert diff . diff_values [ <NUM_LIT:0> ] == ( ( '<STR_LIT:A>' , <NUM_LIT:0> ) , ( True , False ) ) <EOL> assert diff . diff_values [ <NUM_LIT:1> ] == ( ( '<STR_LIT:B>' , <NUM_LIT:1> ) , ( [ <NUM_LIT:1> ] , [ <NUM_LIT:0> ] ) ) <EOL> assert diff . diff_values [ <NUM_LIT:2> ] [ <NUM_LIT:0> ] == ( '<STR_LIT:C>' , <NUM_LIT:1> ) <EOL> assert ( diff . diff_values [ <NUM_LIT:2> ] [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] == [ [ <NUM_LIT:4> , <NUM_LIT:5> ] , [ <NUM_LIT:6> , <NUM_LIT:7> ] ] ) . all ( ) <EOL> assert ( diff . diff_values [ <NUM_LIT:2> ] [ <NUM_LIT:1> ] [ <NUM_LIT:1> ] == [ [ <NUM_LIT:5> , <NUM_LIT:6> ] , [ <NUM_LIT:7> , <NUM_LIT:8> ] ] ) . all ( ) <EOL> assert diff . diff_values [ <NUM_LIT:3> ] == ( ( '<STR_LIT:D>' , <NUM_LIT:0> ) , ( <NUM_LIT:0> , <NUM_LIT> ) ) <EOL> assert diff . diff_values [ <NUM_LIT:4> ] == ( ( '<STR_LIT:E>' , <NUM_LIT:1> ) , ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> assert diff . diff_values [ <NUM_LIT:5> ] == ( ( '<STR_LIT:F>' , <NUM_LIT:0> ) , ( <NUM_LIT:0.0> , <NUM_LIT:1.0> ) ) <EOL> assert diff . diff_values [ <NUM_LIT:6> ] == ( ( '<STR_LIT:F>' , <NUM_LIT:1> ) , ( <NUM_LIT:1.0> , <NUM_LIT> ) ) <EOL> assert diff . diff_values [ <NUM_LIT:7> ] == ( ( '<STR_LIT>' , <NUM_LIT:0> ) , ( <NUM_LIT:0.0> , <NUM_LIT> ) ) <EOL> assert diff . diff_values [ <NUM_LIT:8> ] == ( ( '<STR_LIT>' , <NUM_LIT:1> ) , ( <NUM_LIT:1.0> , <NUM_LIT> ) ) <EOL> assert diff . diff_values [ <NUM_LIT:9> ] == ( ( '<STR_LIT:H>' , <NUM_LIT:0> ) , ( <NUM_LIT:0.0> + <NUM_LIT> , <NUM_LIT:1.0> + <NUM_LIT> ) ) <EOL> assert diff . diff_values [ <NUM_LIT:10> ] == ( ( '<STR_LIT:I>' , <NUM_LIT:0> ) , ( <NUM_LIT> + <NUM_LIT> , <NUM_LIT> + <NUM_LIT> ) ) <EOL> assert diff . diff_values [ <NUM_LIT:11> ] [ <NUM_LIT:0> ] == ( '<STR_LIT>' , <NUM_LIT:0> ) <EOL> assert ( diff . diff_values [ <NUM_LIT:11> ] [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] == [ <NUM_LIT:0> , <NUM_LIT:1> ] ) . all ( ) <EOL> assert ( diff . diff_values [ <NUM_LIT:11> ] [ <NUM_LIT:1> ] [ <NUM_LIT:1> ] == [ <NUM_LIT:1> , <NUM_LIT:2> ] ) . all ( ) <EOL> assert diff . diff_values [ <NUM_LIT:12> ] [ <NUM_LIT:0> ] == ( '<STR_LIT>' , <NUM_LIT:1> ) <EOL> assert ( diff . diff_values [ <NUM_LIT:12> ] [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] == [ <NUM_LIT:2> , <NUM_LIT:3> ] ) . all ( ) <EOL> assert ( diff . diff_values [ <NUM_LIT:12> ] [ <NUM_LIT:1> ] [ <NUM_LIT:1> ] == [ <NUM_LIT:3> , <NUM_LIT:4> ] ) . all ( ) <EOL> assert diff . diff_total == <NUM_LIT> <EOL> assert diff . diff_ratio == <NUM_LIT> <EOL> def test_identical_files_basic ( self ) : <EOL> """<STR_LIT>""" <EOL> a = np . arange ( <NUM_LIT:100> ) . reshape ( ( <NUM_LIT:10> , <NUM_LIT:10> ) ) <EOL> hdu = PrimaryHDU ( data = a ) <EOL> hdu . writeto ( self . temp ( '<STR_LIT>' ) ) <EOL> hdu . writeto ( self . temp ( '<STR_LIT>' ) ) <EOL> diff = FITSDiff ( self . temp ( '<STR_LIT>' ) , self . temp ( '<STR_LIT>' ) ) <EOL> assert diff . identical <EOL> report = diff . report ( ) <EOL> assert '<STR_LIT>' not in report <EOL> assert '<STR_LIT>' not in report <EOL> assert '<STR_LIT>' in report <EOL> def test_partially_identical_files1 ( self ) : <EOL> """<STR_LIT>""" <EOL> a = np . arange ( <NUM_LIT:100> ) . reshape ( ( <NUM_LIT:10> , <NUM_LIT:10> ) ) <EOL> phdu = PrimaryHDU ( data = a ) <EOL> ehdu = ImageHDU ( data = a ) <EOL> hdula = HDUList ( [ phdu , ehdu ] ) <EOL> hdulb = HDUList ( [ phdu , ehdu , ehdu ] ) <EOL> diff = FITSDiff ( hdula , hdulb ) <EOL> assert not diff . identical <EOL> assert diff . diff_hdu_count == ( <NUM_LIT:2> , <NUM_LIT:3> ) <EOL> assert diff . diff_hdus == [ ] <EOL> report = diff . report ( ) <EOL> assert '<STR_LIT>' in report <EOL> assert '<STR_LIT>' in report <EOL> assert '<STR_LIT>' in report <EOL> def test_partially_identical_files2 ( self ) : <EOL> """<STR_LIT>""" <EOL> a = np . arange ( <NUM_LIT:100> ) . reshape ( ( <NUM_LIT:10> , <NUM_LIT:10> ) ) <EOL> phdu = PrimaryHDU ( data = a ) <EOL> ehdu = ImageHDU ( data = a ) <EOL> ehdu2 = ImageHDU ( data = ( a + <NUM_LIT:1> ) ) <EOL> hdula = HDUList ( [ phdu , ehdu , ehdu ] ) <EOL> hdulb = HDUList ( [ phdu , ehdu2 , ehdu ] ) <EOL> diff = FITSDiff ( hdula , hdulb ) <EOL> assert not diff . identical <EOL> assert diff . diff_hdu_count == ( ) <EOL> assert len ( diff . diff_hdus ) == <NUM_LIT:1> <EOL> assert diff . diff_hdus [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] == <NUM_LIT:1> <EOL> hdudiff = diff . diff_hdus [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] <EOL> assert not hdudiff . identical <EOL> assert hdudiff . diff_extnames == ( ) <EOL> assert hdudiff . diff_extvers == ( ) <EOL> assert hdudiff . diff_extension_types == ( ) <EOL> assert hdudiff . diff_headers . identical <EOL> assert not hdudiff . diff_data is None <EOL> datadiff = hdudiff . diff_data <EOL> assert isinstance ( datadiff , ImageDataDiff ) <EOL> assert not datadiff . identical <EOL> assert datadiff . diff_dimensions == ( ) <EOL> assert ( datadiff . diff_pixels == <EOL> [ ( ( <NUM_LIT:0> , y ) , ( y , y + <NUM_LIT:1> ) ) for y in range ( <NUM_LIT:10> ) ] ) <EOL> assert datadiff . diff_ratio == <NUM_LIT:1.0> <EOL> assert datadiff . diff_total == <NUM_LIT:100> <EOL> report = diff . report ( ) <EOL> assert '<STR_LIT>' not in report <EOL> assert '<STR_LIT>' not in report <EOL> assert '<STR_LIT>' in report <EOL> assert '<STR_LIT>' not in report <EOL> assert '<STR_LIT>' in report <EOL> for y in range ( <NUM_LIT:10> ) : <EOL> assert '<STR_LIT>' % ( y + <NUM_LIT:1> ) in report <EOL> assert '<STR_LIT>' in report <EOL> def test_diff_nans ( self ) : <EOL> """<STR_LIT>""" <EOL> arr = np . empty ( ( <NUM_LIT:10> , <NUM_LIT:10> ) , dtype = np . float64 ) <EOL> arr [ : <NUM_LIT:5> ] = <NUM_LIT:1.0> <EOL> arr [ <NUM_LIT:5> : ] = np . nan <EOL> arr2 = arr . copy ( ) <EOL> table = np . rec . array ( [ ( <NUM_LIT:1.0> , <NUM_LIT> ) , ( <NUM_LIT> , np . nan ) , ( np . nan , np . nan ) ] , <EOL> names = [ '<STR_LIT>' , '<STR_LIT>' ] ) . view ( fits . FITS_rec ) <EOL> table2 = table . copy ( ) <EOL> assert ImageDataDiff ( arr , arr2 ) . identical <EOL> assert TableDataDiff ( table , table2 ) . identical <EOL> arr2 [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] = <NUM_LIT> <EOL> arr2 [ <NUM_LIT:5> ] [ <NUM_LIT:0> ] = <NUM_LIT> <EOL> table2 [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] = <NUM_LIT> <EOL> table2 [ <NUM_LIT:1> ] [ <NUM_LIT:1> ] = <NUM_LIT> <EOL> diff = ImageDataDiff ( arr , arr2 ) <EOL> assert not diff . identical <EOL> assert diff . diff_pixels [ <NUM_LIT:0> ] == ( ( <NUM_LIT:0> , <NUM_LIT:0> ) , ( <NUM_LIT:1.0> , <NUM_LIT> ) ) <EOL> assert diff . diff_pixels [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] == ( <NUM_LIT:5> , <NUM_LIT:0> ) <EOL> assert np . isnan ( diff . diff_pixels [ <NUM_LIT:1> ] [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] ) <EOL> assert diff . diff_pixels [ <NUM_LIT:1> ] [ <NUM_LIT:1> ] [ <NUM_LIT:1> ] == <NUM_LIT> <EOL> diff = TableDataDiff ( table , table2 ) <EOL> assert not diff . identical <EOL> assert diff . diff_values [ <NUM_LIT:0> ] == ( ( '<STR_LIT>' , <NUM_LIT:0> ) , ( <NUM_LIT:1.0> , <NUM_LIT> ) ) <EOL> assert diff . diff_values [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] == ( '<STR_LIT>' , <NUM_LIT:1> ) <EOL> assert np . isnan ( diff . diff_values [ <NUM_LIT:1> ] [ <NUM_LIT:1> ] [ <NUM_LIT:0> ] ) <EOL> assert diff . diff_values [ <NUM_LIT:1> ] [ <NUM_LIT:1> ] [ <NUM_LIT:1> ] == <NUM_LIT> <EOL> def test_diff_types ( self ) : <EOL> """<STR_LIT>""" <EOL> f = StringIO ( ) <EOL> a = <NUM_LIT:1.0> <EOL> b = '<STR_LIT:1.0>' <EOL> report_diff_values ( f , a , b ) <EOL> out = f . getvalue ( ) <EOL> assert out . lstrip ( '<STR_LIT:u>' ) == "<STR_LIT>" <EOL> def test_float_comparison ( self ) : <EOL> """<STR_LIT>""" <EOL> f = StringIO ( ) <EOL> a = np . float32 ( <NUM_LIT> ) <EOL> b = np . float32 ( <NUM_LIT> ) <EOL> report_diff_values ( f , a , b ) <EOL> out = f . getvalue ( ) <EOL> assert '<STR_LIT>' in out <EOL> assert '<STR_LIT>' in out <EOL> def test_file_output_from_path_string ( self ) : <EOL> outpath = self . temp ( '<STR_LIT>' ) <EOL> ha = Header ( [ ( '<STR_LIT:A>' , <NUM_LIT:1> ) , ( '<STR_LIT:B>' , <NUM_LIT:2> ) , ( '<STR_LIT:C>' , <NUM_LIT:3> ) ] ) <EOL> hb = ha . copy ( ) <EOL> hb [ '<STR_LIT:C>' ] = <NUM_LIT:4> <EOL> diffobj = HeaderDiff ( ha , hb ) <EOL> diffobj . report ( fileobj = outpath ) <EOL> report_as_string = diffobj . report ( ) <EOL> assert open ( outpath ) . read ( ) == report_as_string <EOL> def test_file_output_clobber_safety ( self ) : <EOL> outpath = self . temp ( '<STR_LIT>' ) <EOL> ha = Header ( [ ( '<STR_LIT:A>' , <NUM_LIT:1> ) , ( '<STR_LIT:B>' , <NUM_LIT:2> ) , ( '<STR_LIT:C>' , <NUM_LIT:3> ) ] ) <EOL> hb = ha . copy ( ) <EOL> hb [ '<STR_LIT:C>' ] = <NUM_LIT:4> <EOL> diffobj = HeaderDiff ( ha , hb ) <EOL> diffobj . report ( fileobj = outpath ) <EOL> assert_raises ( IOError , lambda p : diffobj . report ( fileobj = p ) , <EOL> outpath ) <EOL> def test_file_output_clobber_success ( self ) : <EOL> outpath = self . temp ( '<STR_LIT>' ) <EOL> ha = Header ( [ ( '<STR_LIT:A>' , <NUM_LIT:1> ) , ( '<STR_LIT:B>' , <NUM_LIT:2> ) , ( '<STR_LIT:C>' , <NUM_LIT:3> ) ] ) <EOL> hb = ha . copy ( ) <EOL> hb [ '<STR_LIT:C>' ] = <NUM_LIT:4> <EOL> diffobj = HeaderDiff ( ha , hb ) <EOL> diffobj . report ( fileobj = outpath ) <EOL> report_as_string = diffobj . report ( ) <EOL> diffobj . report ( fileobj = outpath , clobber = True ) <EOL> assert open ( outpath ) . read ( ) == report_as_string , ( "<STR_LIT>" <EOL> "<STR_LIT>" ) </s>
