當前位置: 首頁>>代碼示例>>Python>>正文


Python Extractor.extract_data方法代碼示例

本文整理匯總了Python中extractor.Extractor.extract_data方法的典型用法代碼示例。如果您正苦於以下問題:Python Extractor.extract_data方法的具體用法?Python Extractor.extract_data怎麽用?Python Extractor.extract_data使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在extractor.Extractor的用法示例。


在下文中一共展示了Extractor.extract_data方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: ExtractorTest

# 需要導入模塊: from extractor import Extractor [as 別名]
# 或者: from extractor.Extractor import extract_data [as 別名]
class ExtractorTest(unittest.TestCase):

    def setUp(self):
        example = "LOQ75625Team LOQ            49% blend std 8mm       21-JUN-2000 12:55:23    30.0"
        self.extractor = Extractor()
        self.extractor.extract_data(example)

    def tearDown(self):
        pass

    def test_extract_valid_instrument_name(self):
        self.assertEqual("LOQ", self.extractor.instrumentname)

    def test_extract_valid_run_number(self):
        self.assertEqual("75625", self.extractor.runnumber)

    def test_extract_valid_run_username(self):
        self.assertEqual("Team LOQ", self.extractor.username)

    def test_extract_valid_run_experimenttitle(self):
        self.assertEqual("49% blend std 8mm", self.extractor.experimenttitle)

    def test_extract_valid_run_startdate(self):
        self.assertEqual("21-JUN-2000", self.extractor.startdate)

    def test_extract_valid_run_starttime(self):
        self.assertEqual("12:55:23", self.extractor.starttime)

    def test_extract_valid_run_charge(self):
        self.assertEqual("30.0", self.extractor.charge)
開發者ID:ISISComputingGroup,項目名稱:VmsJournalFileConverter,代碼行數:32,代碼來源:extractor_test.py

示例2: ConverterTest

# 需要導入模塊: from extractor import Extractor [as 別名]
# 或者: from extractor.Extractor import extract_data [as 別名]
class ConverterTest(unittest.TestCase):

    def setUp(self):
        self.loader = FileLoader()
        self.converter = Converter()
        self.extractor = Extractor()
        self.loader.load_file("logs_old/JOURNAL00.TXT")
        self.converter.read_entries(self.loader.lines)

    def test_read_all_lines(self):
        self.assertTrue(len(self.converter.entries) > 0)
        self.assertEqual(len(self.converter.entries), len(self.loader.lines))

    def test_converted_entries_are_valid(self):
        for i in xrange(len(self.loader.lines)):
            self.extractor.extract_data(self.loader.lines[i])
            self.assertEqual(self.converter.entries[i].instrumentname, self.extractor.instrumentname)
            self.assertEqual(self.converter.entries[i].runnumber, self.extractor.runnumber)
            self.assertEqual(self.converter.entries[i].username, self.extractor.username)
            self.assertEqual(self.converter.entries[i].experimenttitle, self.extractor.experimenttitle)
            self.assertEqual(self.converter.entries[i].startdate, self.extractor.startdate)
            self.assertEqual(self.converter.entries[i].starttime, self.extractor.starttime)
            self.assertEqual(self.converter.entries[i].charge, self.extractor.charge)
開發者ID:ISISComputingGroup,項目名稱:VmsJournalFileConverter,代碼行數:25,代碼來源:converter_test.py

示例3: XMLOutputterTest

# 需要導入模塊: from extractor import Extractor [as 別名]
# 或者: from extractor.Extractor import extract_data [as 別名]
class XMLOutputterTest(unittest.TestCase):

    def setUp(self):
        # open and parse model xml file
        self.fmodel = open("logs_new/model_log.xml")
        self.model_tree = ET.parse(self.fmodel)
        self.model_root = self.model_tree.getroot()
        # create sample experiment data
        example = "LOQ75625Team LOQ            49% blend std 8mm       21-JUN-2000 12:55:23    30.0"
        self.extractor = Extractor()
        self.extractor.extract_data(example)
        self.maxDiff = None

        self.xml_out = XMLOutputter("testlog")
        self.xml_out.write_line(self.extractor)

    def test_instrumentname_matches_model(self):
        instrumentname = self.xml_out.get_xml().findall("./NXentry/instrument_name")[0].text
        self.assertEqual("LOQ", instrumentname)

    def test_instrumentname_attribute_matches_model(self):
        instrumentname = self.xml_out.get_xml().findall("./NXentry/instrument_name")[0]
        self.assertEqual("NX_CHAR[3]", instrumentname.get("NAPItype"))

    def test_username_matches_model(self):
        username = self.xml_out.get_xml().findall("./NXentry/user_name")[0].text
        self.assertEqual("Team LOQ", username)

    def test_username_attribute_matches_model(self):
        username = self.xml_out.get_xml().findall("./NXentry/user_name")[0]
        self.assertEqual("NX_CHAR[8]", username.get("NAPItype"))

    def test_experimenttitle_matches_model(self):
        experimenttitle = self.xml_out.get_xml().findall("./NXentry/title")[0].text
        self.assertEqual("49% blend std 8mm", experimenttitle)

    def test_experimenttitle_attribute_matches_model(self):
        experimenttitle = self.xml_out.get_xml().findall("./NXentry/title")[0]
        self.assertEqual("NX_CHAR[17]", experimenttitle.get("NAPItype"))

    def test_runnumber_matches_model(self):
        runnumber = self.xml_out.get_xml().findall("./NXentry/run_number")[0].text
        self.assertEqual("75625", runnumber)

    def test_runnumber_attribute_matches_model(self):
        runnumber = self.xml_out.get_xml().findall("./NXentry/run_number")[0]
        self.assertEqual("NX_INT32", runnumber.get("NAPItype"))

    def test_starttime_matches_model(self):
        starttime = self.xml_out.get_xml().findall("./NXentry/start_time")[0].text
        self.assertEqual("2000-06-21T12:55:23", starttime)

    def test_starttime_attribute_matches_model(self):
        runnumber = self.xml_out.get_xml().findall("./NXentry/start_time")[0]
        self.assertEqual("NX_CHAR[19]", runnumber.get("NAPItype"))

    def test_charge_matches_model(self):
        charge = self.xml_out.get_xml().findall("./NXentry/proton_charge")[0].text
        self.assertEqual("30.0", charge)

    def test_charge_attribute_matches_model(self):
        charge = self.xml_out.get_xml().findall("./NXentry/proton_charge")[0]
        self.assertEqual("NX_FLOAT32", charge.get("NAPItype"))

    def test_is_outputting(self):
        self.xml_out.output_to_file()
        newlog = open("logs_new/testlog.xml", "r")
        self.assertTrue(len(newlog.readlines()) > 1)
        newlog.close()
開發者ID:ISISComputingGroup,項目名稱:VmsJournalFileConverter,代碼行數:71,代碼來源:xml_outputter_test.py


注:本文中的extractor.Extractor.extract_data方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。