示例#1
0
    def test_different_table_rows(self):
        """
        Test tables taht are otherwise identical but one has more rows than the
        other.
        """

        ca1 = Column('A', format='L', array=[True, False])
        cb1 = Column('B', format='L', array=[True, False])
        ca2 = Column('A', format='L', array=[True, False, True])
        cb2 = Column('B', format='L', array=[True, False, True])

        ta = new_table([ca1, cb1])
        tb = new_table([ca2, cb2])

        diff = TableDataDiff(ta.data, tb.data)

        assert_false(diff.identical)
        assert_equal(diff.diff_column_count, ())
        assert_equal(len(diff.common_columns), 2)
        assert_equal(diff.diff_rows, (2, 3))
        assert_equal(diff.diff_values, [])

        report = diff.report()

        assert_true('Table rows differ' in report)
        assert_true('a: 2' in report)
        assert_true('b: 3' in report)
        assert_true('No further data comparison performed.')
示例#2
0
    def test_identical_tables(self):
        c1 = Column('A', format='L', array=[True, False])
        c2 = Column('B', format='X', array=[[0], [1]])
        c3 = Column('C', format='4I', dim='(2, 2)',
                    array=[[0, 1, 2, 3], [4, 5, 6, 7]])
        c4 = Column('D', format='J', bscale=2.0, array=[0, 1])
        c5 = Column('E', format='A3', array=['abc', 'def'])
        c6 = Column('F', format='E', unit='m', array=[0.0, 1.0])
        c7 = Column('G', format='D', bzero=-0.1, array=[0.0, 1.0])
        c8 = Column('H', format='C', array=[0.0+1.0j, 2.0+3.0j])
        c9 = Column('I', format='M', array=[4.0+5.0j, 6.0+7.0j])
        c10 = Column('J', format='PI(2)', array=[[0, 1], [2, 3]])

        columns = [c1, c2, c3, c4, c5, c6, c7, c8, c9, c10]

        ta = new_table(columns)
        tb = new_table([c.copy() for c in columns])

        diff = TableDataDiff(ta.data, tb.data)
        assert_true(diff.identical)
        assert_equal(len(diff.common_columns), 10)
        assert_equal(diff.common_column_names,
                     set(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']))
        assert_equal(diff.diff_ratio, 0)
        assert_equal(diff.diff_total, 0)
示例#3
0
文件: test_diff.py 项目: coleb/PyFITS
    def test_different_table_rows(self):
        """
        Test tables taht are otherwise identical but one has more rows than the
        other.
        """

        ca1 = Column('A', format='L', array=[True, False])
        cb1 = Column('B', format='L', array=[True, False])
        ca2 = Column('A', format='L', array=[True, False, True])
        cb2 = Column('B', format='L', array=[True, False, True])

        ta = new_table([ca1, cb1])
        tb = new_table([ca2, cb2])

        diff = TableDataDiff(ta.data, tb.data)

        assert not diff.identical
        assert diff.diff_column_count == ()
        assert len(diff.common_columns) == 2
        assert diff.diff_rows == (2, 3)
        assert diff.diff_values == []

        report = diff.report()

        assert 'Table rows differ' in report
        assert 'a: 2' in report
        assert 'b: 3' in report
        assert 'No further data comparison performed.'
示例#4
0
    def test_different_table_data(self):
        """
        Test diffing table data on columns of several different data formats
        and dimensions.
        """

        ca1 = Column('A', format='L', array=[True, False])
        ca2 = Column('B', format='X', array=[[0], [1]])
        ca3 = Column('C', format='4I', dim='(2, 2)',
                     array=[[0, 1, 2, 3], [4, 5, 6, 7]])
        ca4 = Column('D', format='J', bscale=2.0, array=[0.0, 2.0])
        ca5 = Column('E', format='A3', array=['abc', 'def'])
        ca6 = Column('F', format='E', unit='m', array=[0.0, 1.0])
        ca7 = Column('G', format='D', bzero=-0.1, array=[0.0, 1.0])
        ca8 = Column('H', format='C', array=[0.0+1.0j, 2.0+3.0j])
        ca9 = Column('I', format='M', array=[4.0+5.0j, 6.0+7.0j])
        ca10 = Column('J', format='PI(2)', array=[[0, 1], [2, 3]])

        cb1 = Column('A', format='L', array=[False, False])
        cb2 = Column('B', format='X', array=[[0], [0]])
        cb3 = Column('C', format='4I', dim='(2, 2)',
                     array=[[0, 1, 2, 3], [5, 6, 7, 8]])
        cb4 = Column('D', format='J', bscale=2.0, array=[2.0, 2.0])
        cb5 = Column('E', format='A3', array=['abc', 'ghi'])
        cb6 = Column('F', format='E', unit='m', array=[1.0, 2.0])
        cb7 = Column('G', format='D', bzero=-0.1, array=[2.0, 3.0])
        cb8 = Column('H', format='C', array=[1.0+1.0j, 2.0+3.0j])
        cb9 = Column('I', format='M', array=[5.0+5.0j, 6.0+7.0j])
        cb10 = Column('J', format='PI(2)', array=[[1, 2], [3, 4]])

        ta = new_table([ca1, ca2, ca3, ca4, ca5, ca6, ca7, ca8, ca9, ca10])
        tb = new_table([cb1, cb2, cb3, cb4, cb5, cb6, cb7, cb8, cb9, cb10])

        diff = TableDataDiff(ta.data, tb.data, numdiffs=20)
        assert_false(diff.identical)
        # The column definitions are the same, but not the column values
        assert_equal(diff.diff_columns, ())
        assert_equal(diff.diff_values[0], (('A', 0), (True, False)))
        assert_equal(diff.diff_values[1], (('B', 1), ([1], [0])))
        assert_equal(diff.diff_values[2][0], ('C', 1))
        assert_true((diff.diff_values[2][1][0] == [[4, 5], [6, 7]]).all())
        assert_true((diff.diff_values[2][1][1] == [[5, 6], [7, 8]]).all())
        assert_equal(diff.diff_values[3], (('D', 0), (0, 2.0)))
        assert_equal(diff.diff_values[4], (('E', 1), ('def', 'ghi')))
        assert_equal(diff.diff_values[5], (('F', 0), (0.0, 1.0)))
        assert_equal(diff.diff_values[6], (('F', 1), (1.0, 2.0)))
        assert_equal(diff.diff_values[7], (('G', 0), (0.0, 2.0)))
        assert_equal(diff.diff_values[8], (('G', 1), (1.0, 3.0)))
        assert_equal(diff.diff_values[9], (('H', 0), (0.0+1.0j, 1.0+1.0j)))
        assert_equal(diff.diff_values[10], (('I', 0), (4.0+5.0j, 5.0+5.0j)))
        assert_equal(diff.diff_values[11][0], ('J', 0))
        assert_true((diff.diff_values[11][1][0] == [0, 1]).all())
        assert_true((diff.diff_values[11][1][1] == [1, 2]).all())
        assert_equal(diff.diff_values[12][0], ('J', 1))
        assert_true((diff.diff_values[12][1][0] == [2, 3]).all())
        assert_true((diff.diff_values[12][1][1] == [3, 4]).all())

        assert_equal(diff.diff_total, 13)
        assert_equal(diff.diff_ratio, 0.65)
示例#5
0
    def test_different_table_field_names(self):
        ca = Column('A', format='L', array=[True, False])
        cb = Column('B', format='L', array=[True, False])
        cc = Column('C', format='L', array=[True, False])

        ta = new_table([ca, cb])
        tb = new_table([ca, cc])

        diff = TableDataDiff(ta.data, tb.data)

        assert_false(diff.identical)
        assert_equal(len(diff.common_columns), 1)
        assert_equal(diff.common_column_names, set(['a']))
        assert_equal(diff.diff_column_names, (['B'], ['C']))
        assert_equal(diff.diff_ratio, 0)
        assert_equal(diff.diff_total, 0)
示例#6
0
文件: test_diff.py 项目: coleb/PyFITS
    def test_different_table_field_names(self):
        ca = Column('A', format='L', array=[True, False])
        cb = Column('B', format='L', array=[True, False])
        cc = Column('C', format='L', array=[True, False])

        ta = new_table([ca, cb])
        tb = new_table([ca, cc])

        diff = TableDataDiff(ta.data, tb.data)

        assert not diff.identical
        assert len(diff.common_columns) == 1
        assert diff.common_column_names == set(['a'])
        assert diff.diff_column_names == (['B'], ['C'])
        assert diff.diff_ratio == 0
        assert diff.diff_total == 0
示例#7
0
    def _clone(self, shape):
        """
        Overload this to make mask array indexing work properly.
        """

        from pyfits.hdu.table import new_table

        hdu = new_table(self._coldefs, nrows=shape[0])
        return hdu.data
示例#8
0
    def _clone(self, shape):
        """
        Overload this to make mask array indexing work properly.
        """

        from pyfits.hdu.table import new_table

        hdu = new_table(self._coldefs, nrows=shape[0])
        return hdu.data
示例#9
0
    def test_ignore_table_fields(self):
        c1 = Column('A', format='L', array=[True, False])
        c2 = Column('B', format='X', array=[[0], [1]])
        c3 = Column('C', format='4I', dim='(2, 2)',
                    array=[[0, 1, 2, 3], [4, 5, 6, 7]])

        c4 = Column('B', format='X', array=[[1], [0]])
        c5 = Column('C', format='4I', dim='(2, 2)',
                    array=[[1, 2, 3, 4], [5, 6, 7, 8]])

        ta = new_table([c1, c2, c3])
        tb = new_table([c1, c4, c5])

        diff = TableDataDiff(ta.data, tb.data, ignore_fields=['B', 'C'])
        assert_true(diff.identical)

        # The only common column should be c1
        assert_equal(len(diff.common_columns), 1)
        assert_equal(diff.common_column_names, set(['a']))
        assert_equal(diff.diff_ratio, 0)
        assert_equal(diff.diff_total, 0)
示例#10
0
    def test_different_table_field_counts(self):
        """
        Test tables with some common columns, but different number of columns
        overall.
        """

        ca = Column('A', format='L', array=[True, False])
        cb = Column('B', format='L', array=[True, False])
        cc = Column('C', format='L', array=[True, False])

        ta = new_table([cb])
        tb = new_table([ca, cb, cc])

        diff = TableDataDiff(ta.data, tb.data)

        assert_false(diff.identical)
        assert_equal(diff.diff_column_count, (1, 3))
        assert_equal(len(diff.common_columns), 1)
        assert_equal(diff.common_column_names, set(['b']))
        assert_equal(diff.diff_column_names, ([], ['A', 'C']))
        assert_equal(diff.diff_ratio, 0)
        assert_equal(diff.diff_total, 0)
示例#11
0
文件: test_diff.py 项目: coleb/PyFITS
    def test_different_table_field_counts(self):
        """
        Test tables with some common columns, but different number of columns
        overall.
        """

        ca = Column('A', format='L', array=[True, False])
        cb = Column('B', format='L', array=[True, False])
        cc = Column('C', format='L', array=[True, False])

        ta = new_table([cb])
        tb = new_table([ca, cb, cc])

        diff = TableDataDiff(ta.data, tb.data)

        assert not diff.identical
        assert diff.diff_column_count == (1, 3)
        assert len(diff.common_columns) == 1
        assert diff.common_column_names == set(['b'])
        assert diff.diff_column_names == ([], ['A', 'C'])
        assert diff.diff_ratio == 0
        assert diff.diff_total == 0
示例#12
0
    def test_diff_empty_tables(self):
        """
        Regression test for #178.

        Ensure that diffing tables containing empty data doesn't crash.
        """

        c1 = Column('D', format='J')
        c2 = Column('E', format='J')
        thdu = new_table([c1, c2], nrows=0)

        hdula = pyfits.HDUList([thdu])
        hdulb = pyfits.HDUList([thdu])

        diff = FITSDiff(hdula, hdulb)
        assert_true(diff.identical)
示例#13
0
文件: test_diff.py 项目: coleb/PyFITS
    def test_diff_empty_tables(self):
        """
        Regression test for https://trac.assembla.com/pyfits/ticket/178

        Ensure that diffing tables containing empty data doesn't crash.
        """

        c1 = Column('D', format='J')
        c2 = Column('E', format='J')
        thdu = new_table([c1, c2], nrows=0)

        hdula = fits.HDUList([thdu])
        hdulb = fits.HDUList([thdu])

        diff = FITSDiff(hdula, hdulb)
        assert diff.identical