Пример #1
0
    def test_ExcelWrapper(self):
        logging.debug('')
        logging.debug('test_ExcelWrapper')

        from excel_wrapper.excel_wrapper import ExcelWrapper
        excelFile = r"excel_wrapper_test.xlsx"
        xmlFile = r"excel_wrapper_test.xml"
        ew = ExcelWrapper(excelFile, xmlFile)
        ew.execute()
        assert_rel_error(self, ew.y, 2.12345, 0.0001)
        self.assertEqual(not ew.b, ew.bout, msg='excel_wrapper could not handle a Bool variable')
        self.assertEqual(ew.s.lower(), ew.sout, msg='excel_wrapper couldn not handle a Str variable.')
        del(ew)
        os._exit(1)
Пример #2
0
    def test_ExcelWrapper(self):
        logging.debug('')
        logging.debug('test_ExcelWrapper')

        from excel_wrapper.excel_wrapper import ExcelWrapper
        test_root = os.path.abspath(os.path.dirname(__file__))
        excelFile = os.path.join(test_root, "excel_wrapper_test.xlsx")

        xmlFile = os.path.join(test_root, "excel_wrapper_test.xml")

        ew = ExcelWrapper(excelFile, xmlFile)
        ew.execute()
        assert_rel_error(self, ew.y, 2.12345, 0.0001)
        self.assertEqual(not ew.b,
                         ew.bout,
                         msg='excel_wrapper could not handle a Bool variable')
        self.assertEqual(ew.s.lower(),
                         ew.sout,
                         msg='excel_wrapper couldn not handle a Str variable.')
        del (ew)
        os._exit(1)
    def test_ExcelWrapper(self):
        logging.debug('')
        logging.debug('test_ExcelWrapper')

        from excel_wrapper.excel_wrapper import ExcelWrapper
        test_root = os.path.abspath(os.path.dirname(__file__))
        excelFile = os.path.join(
            test_root,
            "excel_wrapper_test.xlsx"
        )

        xmlFile = os.path.join(
            test_root,
            "excel_wrapper_test.xml"
        )

        ew = ExcelWrapper(excelFile, xmlFile)
        ew.execute()
        assert_rel_error(self, ew.y, 2.12345, 0.0001)
        self.assertEqual(not ew.b, ew.bout, msg='excel_wrapper could not handle a Bool variable')
        self.assertEqual(ew.s.lower(), ew.sout, msg='excel_wrapper couldn not handle a Str variable.')
        del(ew)
        os._exit(1)
Пример #4
0
    def _test_ExcelWrapper(self,
                           varfile,
                           inputs={
                               'x': 10,
                               'b': True,
                               's': u'aSdF',
                               'macroVar': u'macrocheck',
                               'macroVB': 12
                           }):
        prob = Problem()
        root = prob.root = Group()
        this_dir = os.path.dirname(os.path.abspath(__file__))
        excelfile = os.path.join(this_dir, "excel_wrapper_test.xlsm")
        varfile = os.path.join(this_dir, varfile)
        kwargs = {}
        if not varfile.endswith('.json'):
            kwargs['macros'] = ('Macro5', 'Sheet3.Transfer_ColA')
        root.add('ew',
                 ExcelWrapper(excelfile, varfile, **kwargs),
                 promotes=['*'])
        varcomp = IndepVarComp(
            ((name, val) for name, val in six.iteritems(inputs)))
        root.add('vc', varcomp)
        root.connect('vc.x', 'x')
        root.connect('vc.b', 'b')
        root.connect('vc.s', 's')
        root.connect('vc.macroVar', 'macroVar_in')
        root.connect('vc.macroVB', 'macroVB_in')
        prob.setup()
        prob.run()

        self.assertEqual((2.1 * float(prob['x'])), prob['y'])
        self.assertEqual((2.1 * float(inputs['x'])), prob['y'])
        self.assertEqual(inputs['b'], prob['b'])
        self.assertEqual(prob['macroVar_in'], prob['macroVar_out'])
        self.assertEqual(3 * int(prob['macroVB_in']) - 1,
                         int(prob['macroVB_out']))
        self.assertEqual(bool(prob['b']), not prob['bout'])
        self.assertEqual(inputs['s'], prob['s'])
        self.assertEqual(prob['s'].lower(), prob['sout'])
        self.assertEqual(
            float(prob['sheet1_in']) + 100, prob['sheet2_out'],
            "Excel wrapper fails in multiple sheets")