예제 #1
0
    def test_io(self):
        test_file = os.path.join(TEST_FILE_DIR, 'xTESLADIAG_000003_CH68.000')
        json_file = os.path.join(TEST_FILE_DIR, 'xTESLADIAG_000003_CH68.json')
        test_out = 'test1.000'

        procedure = Procedure.from_file(os.path.join(TEST_FILE_DIR, test_file))
        with ScratchDir('.'):
            dumpfn(procedure, json_file)
            procedure.to_file(test_out)
            hash1 = hash_file(test_file)
            hash2 = hash_file(test_out)
            if hash1 != hash2:
                original = open(test_file).readlines()
                parsed = open(test_out).readlines()
                self.assertFalse(list(difflib.unified_diff(original, parsed)))
                for line in difflib.unified_diff(original, parsed):
                    self.assertIsNotNone(line)

        test_file = os.path.join(TEST_FILE_DIR, 'xTESLADIAG_000004_CH69.000')
        json_file = os.path.join(TEST_FILE_DIR, 'xTESLADIAG_000004_CH69.json')
        test_out = 'test2.000'

        procedure = Procedure.from_file(os.path.join(TEST_FILE_DIR, test_file))
        with ScratchDir('.'):
            dumpfn(procedure, json_file)
            procedure.to_file(test_out)
            hash1 = hash_file(test_file)
            hash2 = hash_file(test_out)
            if hash1 != hash2:
                original = open(test_file).readlines()
                parsed = open(test_out).readlines()
                self.assertFalse(list(difflib.unified_diff(original, parsed)))
                for line in difflib.unified_diff(original, parsed):
                    self.assertIsNotNone(line)
예제 #2
0
    def test_serial_conversion(self):
        procedure = Procedure()

        templates = PROCEDURE_TEMPLATE_DIR

        test_file = 'diagnosticV3.000'
        json_file = 'test.json'

        proc_dict = procedure.from_file(os.path.join(templates, test_file))

        test_step_dict = proc_dict['MaccorTestProcedure']['ProcSteps'][
            'TestStep']

        converter = ProcedureToSchedule(test_step_dict)
        step_name_list, step_flow_ctrl = converter.create_metadata()

        for step_index, step in enumerate(test_step_dict):
            if 'Loop' in step['StepType']:
                print(step_index, step)
            step_arbin = converter.compile_to_arbin(test_step_dict[step_index],
                                                    step_index, step_name_list,
                                                    step_flow_ctrl)
            if 'Loop' in step['StepType']:
                self.assertEqual(step_arbin['m_szStepCtrlType'],
                                 'Set Variable(s)')
                self.assertEqual(step_arbin['m_uLimitNum'], '2')
            if step_index == 15:
                self.assertEqual(step_arbin['Limit0']['m_szGotoStep'],
                                 '11-None')
                self.assertEqual(step_arbin['Limit1']['m_szGotoStep'],
                                 'Next Step')
예제 #3
0
    def test_serial_conversion(self):
        procedure = Procedure()

        templates = PROCEDURE_TEMPLATE_DIR

        test_file = "diagnosticV3.000"
        json_file = "test.json"

        proc_dict = procedure.from_file(os.path.join(templates, test_file))

        test_step_dict = proc_dict["MaccorTestProcedure"]["ProcSteps"][
            "TestStep"]

        converter = ProcedureToSchedule(test_step_dict)
        step_name_list, step_flow_ctrl = converter.create_metadata()

        for step_index, step in enumerate(test_step_dict):
            if "Loop" in step["StepType"]:
                print(step_index, step)
            step_arbin = converter.compile_to_arbin(test_step_dict[step_index],
                                                    step_index, step_name_list,
                                                    step_flow_ctrl)
            if "Loop" in step["StepType"]:
                self.assertEqual(step_arbin["m_szStepCtrlType"],
                                 "Set Variable(s)")
                self.assertEqual(step_arbin["m_uLimitNum"], "2")
            if step_index == 15:
                self.assertEqual(step_arbin["Limit0"]["m_szGotoStep"],
                                 "11-None")
                self.assertEqual(step_arbin["Limit1"]["m_szGotoStep"],
                                 "Next Step")
예제 #4
0
    def test_schedule_creation(self):
        procedure = Procedure()

        templates = PROCEDURE_TEMPLATE_DIR

        test_file = 'diagnosticV3.000'
        json_file = 'test.json'
        sdu_test_input = os.path.join(SCHEDULE_TEMPLATE_DIR,
                                      '20170630-3_6C_9per_5C.sdu')
        sdu_test_output = os.path.join(TEST_FILE_DIR,
                                       'schedule_test_output.sdu')

        proc_dict = procedure.from_file(os.path.join(templates, test_file))
        test_step_dict = proc_dict['MaccorTestProcedure']['ProcSteps'][
            'TestStep']

        converter = ProcedureToSchedule(test_step_dict)
        converter.create_sdu(sdu_test_input, sdu_test_output)
        parsed = open(sdu_test_output, encoding='latin-1').readlines()
        self.assertEqual(parsed[329], '[Schedule_Step3_Limit0]\n')
        os.remove(sdu_test_output)
예제 #5
0
    def test_single_step_conversion(self):
        procedure = Procedure()

        templates = PROCEDURE_TEMPLATE_DIR

        test_file = "diagnosticV3.000"
        json_file = "test.json"

        proc_dict = procedure.from_file(os.path.join(templates, test_file))
        test_step_dict = proc_dict["MaccorTestProcedure"]["ProcSteps"][
            "TestStep"]

        converter = ProcedureToSchedule(test_step_dict)
        step_index = 5
        step_name_list, step_flow_ctrl = converter.create_metadata()

        self.assertEqual(step_flow_ctrl[7], "5-reset cycle C/20")
        self.assertEqual(step_flow_ctrl[68], "38-reset cycle")

        step_arbin = converter.compile_to_arbin(test_step_dict[step_index],
                                                step_index, step_name_list,
                                                step_flow_ctrl)
        self.assertEqual(step_arbin["m_szLabel"], "6-None")
        self.assertEqual(step_arbin["Limit0"]["m_szGotoStep"], "Next Step")
        self.assertEqual(step_arbin["Limit0"]["Equation0_szLeft"],
                         "PV_CHAN_Voltage")
        self.assertEqual(step_arbin["Limit2"]["m_szGotoStep"],
                         "70-These are the 2 reset cycles")

        step_index = 8
        step_arbin = converter.compile_to_arbin(test_step_dict[step_index],
                                                step_index, step_name_list,
                                                step_flow_ctrl)

        self.assertEqual(step_arbin["Limit0"]["Equation0_szLeft"],
                         "PV_CHAN_CV_Stage_Current")
        self.assertEqual(
            step_arbin["Limit0"]["Equation0_szRight"],
            test_step_dict[step_index]["Ends"]["EndEntry"][0]["Value"],
        )
예제 #6
0
    def test_single_step_conversion(self):
        procedure = Procedure()

        templates = PROCEDURE_TEMPLATE_DIR

        test_file = 'diagnosticV3.000'
        json_file = 'test.json'

        proc_dict = procedure.from_file(os.path.join(templates, test_file))
        test_step_dict = proc_dict['MaccorTestProcedure']['ProcSteps'][
            'TestStep']

        converter = ProcedureToSchedule(test_step_dict)
        step_index = 5
        step_name_list, step_flow_ctrl = converter.create_metadata()

        self.assertEqual(step_flow_ctrl[7], '5-reset cycle C/20')
        self.assertEqual(step_flow_ctrl[68], '38-reset cycle')

        step_arbin = converter.compile_to_arbin(test_step_dict[step_index],
                                                step_index, step_name_list,
                                                step_flow_ctrl)
        self.assertEqual(step_arbin['m_szLabel'], '6-None')
        self.assertEqual(step_arbin['Limit0']['m_szGotoStep'], 'Next Step')
        self.assertEqual(step_arbin['Limit0']['Equation0_szLeft'],
                         'PV_CHAN_Voltage')
        self.assertEqual(step_arbin['Limit2']['m_szGotoStep'],
                         '70-These are the 2 reset cycles')

        step_index = 8
        step_arbin = converter.compile_to_arbin(test_step_dict[step_index],
                                                step_index, step_name_list,
                                                step_flow_ctrl)

        self.assertEqual(step_arbin['Limit0']['Equation0_szLeft'],
                         'PV_CHAN_CV_Stage_Current')
        self.assertEqual(
            step_arbin['Limit0']['Equation0_szRight'],
            test_step_dict[step_index]['Ends']['EndEntry'][0]['Value'])
예제 #7
0
    def test_procedure_with_waveform(self):
        maccor_waveform_file = os.path.join(TEST_FILE_DIR, "LA4_8rep_lim.MWF")
        test_file = os.path.join(PROCEDURE_TEMPLATE_DIR, "diagnosticV2.000")
        procedure = Procedure.from_file(test_file)
        rest_step = procedure["MaccorTestProcedure"]["ProcSteps"]["TestStep"][
            2]
        end_step = procedure["MaccorTestProcedure"]["ProcSteps"]["TestStep"][
            -1]

        procedure["MaccorTestProcedure"]["ProcSteps"]["TestStep"] = procedure[
            "MaccorTestProcedure"]["ProcSteps"]["TestStep"][:8]
        procedure["MaccorTestProcedure"]["ProcSteps"]["TestStep"][
            5:9] = deepcopy(
                procedure["MaccorTestProcedure"]["ProcSteps"]["TestStep"][4:8])

        procedure.set("MaccorTestProcedure.ProcSteps.TestStep.5",
                      deepcopy(rest_step))

        procedure.set("MaccorTestProcedure.ProcSteps.TestStep.9",
                      deepcopy(rest_step))

        procedure.set("MaccorTestProcedure.ProcSteps.TestStep.10",
                      deepcopy(end_step))

        procedure.set(
            "MaccorTestProcedure.ProcSteps.TestStep.5.Ends.EndEntry.0.Step",
            "007")
        procedure.set(
            "MaccorTestProcedure.ProcSteps.TestStep.8.Ends.EndEntry.Step",
            "010")
        procedure.set(
            "MaccorTestProcedure.ProcSteps.TestStep.9.Ends.EndEntry.0.Step",
            "011")

        procedure = procedure.insert_maccor_waveform_discharge(
            6, maccor_waveform_file)
        for step in procedure["MaccorTestProcedure"]["ProcSteps"]["TestStep"]:
            print(step["Ends"])
            if step["StepType"] in ["Charge", "Dischrge", "Rest"]:
                step["Ends"]["EndEntry"][-1]["Step"] = "011"
                step["Ends"]["EndEntry"][-2]["Step"] = "011"

        steps = [
            x["StepType"]
            for x in procedure["MaccorTestProcedure"]["ProcSteps"]["TestStep"]
        ]
        self.assertEqual(
            steps,
            [
                "Rest",
                "Charge",
                "Rest",
                "Do 1",
                "Charge",
                "Rest",
                "FastWave",
                "AdvCycle",
                "Loop 1",
                "Rest",
                "End",
            ],
        )
        self.assertEqual(
            procedure["MaccorTestProcedure"]["ProcSteps"]["TestStep"][5]
            ["Ends"]["EndEntry"][0]["Step"],
            "007",
        )
        self.assertEqual(
            procedure["MaccorTestProcedure"]["ProcSteps"]["TestStep"][6]
            ["StepType"],
            "FastWave",
        )

        with ScratchDir(".") as scratch_dir:
            local_name = "test_mwf_LA4_lim.000"
            procedure.to_file(os.path.join(scratch_dir, local_name))