def test_numNonsharedFields_separateDim_differentNumberOfSlices(self):
        # Doing diffs with a separate_dim, where variable has a different number
        # of slices in the two variables. There should be one nonshared field
        # for each missing slice. Note that we treat this as non-shared, rather
        # than a dim-diff; this feels like the right thing to do, both in terms
        # of:
        # - By analogy to the fact that we treat each time slice as a separate
        #   variable for the sake of analysis
        # - It seems like this is more likely to do the Right Thing in the case
        #   of intentional / expected differences in the number of time slices in
        #   the file
        data1 = np.array([[1,2,3,4],[5,6,7,8]])
        data2 = np.array([[1,2],[5,6]])
        file1 = NetcdfFileFake(
            self.FILENAME1,
            variables = {'var1': NetcdfVariableFake(data1, ('dim1', 'dim2'))})
        file2 = NetcdfFileFake(
            self.FILENAME2,
            variables = {'var1': NetcdfVariableFake(data2, ('dim1', 'dim2'))})
        mydiffs = FileDiffs(file1, file2, separate_dim='dim2')
        num_nonshared = mydiffs.num_nonshared_fields()
        self.assertEqual(num_nonshared, 2)

        # Also make sure that other counts are correct in this case
        self.assertEqual(mydiffs.num_vars(), 4)
        self.assertEqual(mydiffs.num_vars_differ(), 0)
        self.assertEqual(mydiffs.num_dims_differ(), 0)
Beispiel #2
0
    def test_numNonsharedFields_separateDim_differentNumberOfSlices(self):
        # Doing diffs with a separate_dim, where variable has a different number
        # of slices in the two variables. There should be one nonshared field
        # for each missing slice. Note that we treat this as non-shared, rather
        # than a dim-diff; this feels like the right thing to do, both in terms
        # of:
        # - By analogy to the fact that we treat each time slice as a separate
        #   variable for the sake of analysis
        # - It seems like this is more likely to do the Right Thing in the case
        #   of intentional / expected differences in the number of time slices in
        #   the file
        data1 = np.array([[1, 2, 3, 4], [5, 6, 7, 8]])
        data2 = np.array([[1, 2], [5, 6]])
        file1 = NetcdfFileFake(
            self.FILENAME1,
            variables={'var1': NetcdfVariableFake(data1, ('dim1', 'dim2'))})
        file2 = NetcdfFileFake(
            self.FILENAME2,
            variables={'var1': NetcdfVariableFake(data2, ('dim1', 'dim2'))})
        mydiffs = FileDiffs(file1, file2, separate_dim='dim2')
        num_nonshared = mydiffs.num_nonshared_fields()
        self.assertEqual(num_nonshared, 2)

        # Also make sure that other counts are correct in this case
        self.assertEqual(mydiffs.num_vars(), 4)
        self.assertEqual(mydiffs.num_vars_differ(), 0)
        self.assertEqual(mydiffs.num_dims_differ(), 0)
 def test_numDimsDiffer_with3Vars(self):
     file1 = NetcdfFileFake(
         self.FILENAME1,
         variables = {'var1': NetcdfVariableFake(np.array([1,2,3])),
                      'var2': NetcdfVariableFake(np.array([4,5,6])),
                      'var3': NetcdfVariableFake(np.array([7,8,9]))})
     file2 = NetcdfFileFake(
         self.FILENAME2,
         variables = {'var1': NetcdfVariableFake(np.array([1,2])),       # differs
                      'var2': NetcdfVariableFake(np.array([4,5,6])),     # same
                      'var3': NetcdfVariableFake(np.array([7,8,9,10]))}) # differs
     mydiffs = FileDiffs(file1, file2, separate_dim=None)
     num_differ = mydiffs.num_dims_differ()
     self.assertEqual(num_differ, 2)
Beispiel #4
0
 def test_numDimsDiffer_with3Vars(self):
     file1 = NetcdfFileFake(self.FILENAME1,
                            variables={
                                'var1':
                                NetcdfVariableFake(np.array([1, 2, 3])),
                                'var2':
                                NetcdfVariableFake(np.array([4, 5, 6])),
                                'var3':
                                NetcdfVariableFake(np.array([7, 8, 9]))
                            })
     file2 = NetcdfFileFake(
         self.FILENAME2,
         variables={
             'var1': NetcdfVariableFake(np.array([1, 2])),  # differs
             'var2': NetcdfVariableFake(np.array([4, 5, 6])),  # same
             'var3': NetcdfVariableFake(np.array([7, 8, 9, 10]))
         })  # differs
     mydiffs = FileDiffs(file1, file2, separate_dim=None)
     num_differ = mydiffs.num_dims_differ()
     self.assertEqual(num_differ, 2)