Esempio n. 1
0
    def test_read_write(self):
        fixture_filename = os.path.join(os.path.dirname(__file__), 'fixtures', 'example-model.xlsx')

        model = Reader().run(fixture_filename)[Model][0]
        self.assertEqual(model.validate(), None)

        # compare excel files
        Writer().run(self.filename, model, data_repo_metadata=False)
        original = read_workbook(fixture_filename)
        copy = read_workbook(self.filename)
        remove_ws_metadata(original)
        remove_ws_metadata(copy)
        original.pop('!!' + obj_tables.core.TOC_SHEET_NAME)
        copy.pop('!!' + obj_tables.core.TOC_SHEET_NAME)

        # note that models must be sorted by id for this assertion to hold
        for sheet in original.keys():
            for i_row, (copy_row, original_row) in enumerate(zip(copy[sheet], original[sheet])):
                self.assertEqual(copy_row, original_row,
                                 msg='Rows {} of {} sheets are not equal'.format(i_row, sheet))
            self.assertEqual(copy[sheet], original[sheet], msg='{} sheets are not equal'.format(sheet))

        self.assertEqual(copy, original)

        # compare models
        model2 = Reader().run(self.filename)[Model][0]
        self.assertTrue(model2.is_equal(model))
        self.assertTrue(model.difference(model2) == '')
Esempio n. 2
0
    def _default(self):
        args = self.app.pargs

        if args.compare_files:
            model1 = read_workbook(args.path_1)
            model2 = read_workbook(args.path_2)
            if not args.compare_metadata_in_files:
                self.remove_metadata(model1)
                self.remove_metadata(model2)

            diff = model1.difference(model2)

        else:
            model1 = Reader().run(args.path_1)[Model][0]
            model2 = Reader().run(args.path_2)[Model][0]
            diff = model1.difference(model2)

        if diff:
            print(diff)
        else:
            print('Models are identical')