Ejemplo n.º 1
0
    def test_upper_lower(self):
        # 测试一下大小写搜索是否正常
        test_file_path = "/Users/L1n/Desktop/Python Projects/PyCharm/文件内容搜索器/搜索器测试代码/05_ra/03_SZT1106_ra_tables.sql"

        # 全大写搜索
        self.assertEqual(search_keyword_infile(test_file_path, "RA.TBCODECERTCLASS"),
                         "CREATE TABLE RA.tbCodeCertClass(")

        # 全小写搜索
        self.assertEqual(search_keyword_infile(test_file_path, "ra.tbcodecertclass"),
                         "CREATE TABLE RA.tbCodeCertClass(")

        # 大小写搜索
        self.assertEqual(search_keyword_infile(test_file_path, "RA.tbCodeCertClass"),
                         "CREATE TABLE RA.tbCodeCertClass(")
Ejemplo n.º 2
0
 def test_search_gbk_comment(self):
     """
     测试是否能够搜索到 gbk 编码的注释
     :return:
     """
     test_path = "/Users/L1n/Desktop/Python Projects/PyCharm/文件内容搜索器/cacfg_src_v3.60.0010/PMDlgPersonCert.cpp"
     self.assertEqual(search_keyword_infile(test_path, "读存储"), '		AfxMessageBox("读存储设备出错!");')
Ejemplo n.º 3
0
    def begin_search(self, root_path, file_type, ignore_case, keyword):
        counts = 0
        for root, dirs, files in os.walk(root_path):
            for each_file in files:
                if is_valid_file_type(each_file, file_type):
                    path = root + os.sep + each_file
                    line_content = search_keyword_infile(
                        path, keyword, ignore_case)
                    if line_content:
                        self.result_table.insertRow(counts)

                        content_path = QTableWidgetItem(".{}".format(
                            path[len(root_path):]))
                        self.result_table.setItem(counts, 0, content_path)

                        content = QTableWidgetItem(line_content.strip())
                        self.result_table.setItem(counts, 1, content)

                        counts += 1
                        self.result_table.setRowCount(counts)

        self.state_label.setText("搜索结束")