Beispiel #1
0
    def test_replace_string_in_file(self):
        test_name = 'gbk.txt'
        ori_data = '这是一个文件,用于进行测试。what are you doing.'
        file_name = myfile.get_real_dir(__modpath__) + os.sep + test_name

        expect_data = ori_data
        file_data = myfile.read_file_content(file_name)
        msg_format = 'expecte {0}, but {1}'
        self.assertEqual(expect_data, file_data, msg_format.format(expect_data, file_data))

        enc_result = myfile.detect_file_enc(file_name)
        expect_data = 'gb2312'
        encoding = enc_result['encoding'].lower()
        self.assertEqual(expect_data, encoding, msg_format.format(expect_data, encoding))

        src_dst_list = list(zip(['what'], ['F**k']))
        enc_result = myfile.replace_string_in_file(file_name, src_dst_list)
        expect_data = '这是一个文件,用于进行测试。F**k are you doing.'
        file_data = myfile.read_file_content(file_name)
        self.assertEqual(expect_data, file_data, msg_format.format(expect_data, file_data))

        enc_result = myfile.detect_file_enc(file_name)
        expect_data = 'gb2312'
        encoding = enc_result['encoding'].lower()
        self.assertEqual(expect_data, encoding, msg_format.format(expect_data, encoding))

        myfile.write_to_file(file_name, ori_data, encoding)
Beispiel #2
0
    def test_read_file_first_line(self):
        test_name = r'upgrade.xml'
        file_name = myfile.get_real_dir(__modpath__) + os.sep + test_name
        first_line = myfile.read_file_first_line(file_name)

        expect_data = '<?xml version="1.0" encoding="utf-8"?>\r\n'
        msg_format = 'expecte {0}, but {1}'
        self.assertEqual(expect_data, first_line, msg_format.format(expect_data, first_line))
Beispiel #3
0
    def test_read_file_content(self):
        # GB2312 编码格式文件验证
        ori_content = '这只是一个测试文件。'
        test_name = r'for_test.txt'
        file_name = myfile.get_real_dir(__modpath__) + os.sep + test_name
        readed_content = myfile.read_file_content(file_name)

        msg_format = 'expecte {0}, but {1}'
        self.assertEqual(ori_content, readed_content, msg_format.format(ori_content, readed_content))

        # UTF8 with BOM 编码格式文件验证
        ori_content = 'utf-8-sig及中文验证;'
        test_name = r'utf_8_sig.txt'
        file_name = myfile.get_real_dir(__modpath__) + os.sep + test_name
        readed_content = myfile.read_file_content(file_name)

        msg_format = 'expecte {0}, but {1}'
        self.assertEqual(ori_content, readed_content, msg_format.format(ori_content, readed_content))
    def test_get_file_sha1(self):
        test_name = r'gbk.txt'
        file_name = myfile.get_real_dir(__modpath__) + '\\' + test_name
        file_sha1 = myhash.get_file_sha1(file_name)

        ori_sha1 = '6B497D040B40DDA36C53E7F96BE12390602523B1'
        expected = ori_sha1.lower()
        msg_format = 'expecte {0}, but {1}'
        self.assertEqual(expected, file_sha1.lower(),
                         msg_format.format(expected, file_sha1.lower()))
    def test_get_file_md5(self):
        test_name = r'gbk.txt'
        file_name = myfile.get_real_dir(__modpath__) + '\\' + test_name
        file_md5 = myhash.get_file_md5(file_name)

        ori_md5 = '71BC7781C1AF31B3F50FFF631FA80852'
        expected = ori_md5.lower()
        msg_format = 'expecte {0}, but {1}'
        self.assertEqual(expected, file_md5.lower(),
                         msg_format.format(expected, file_md5.lower()))
Beispiel #6
0
    def test_write_to_file(self):
        content = "info to write"

        dst_name = r'file_output.txt'
        dst_file = myfile.get_real_dir(__modpath__) + os.sep + dst_name
        myfile.write_to_file(dst_file, content)

        readed_content = myfile.read_file_content(dst_file)

        msg_format = 'expecte {0}, but {1}'
        self.assertEqual(content, readed_content, msg_format.format(content, readed_content))
Beispiel #7
0
def test_read_valid_string_list_from_file():
    test_name = r'AndroidManifest.xml'
    file_name = myfile.get_real_dir(__modpath__) + '\\' + test_name
    updater = apk_builder.VersionConfigUpdater(file_name, False)

    print('original version code: ' + updater.version_code)
    print('original version name: ' + updater.version_name)
    print()

    updater.update_version_config()

    print('new version code: ' + updater.version_code)
    print('new version name: ' + updater.version_name)
Beispiel #8
0
    def test_filter_unique_item(self):
        test_name = r'filter_unique_intput.txt'
        file_name = myfile.get_real_dir(__modpath__) + '\\' + test_name
        readed_lines = myfile.read_file_lines(file_name)
        src_list = []
        for item in readed_lines:
            src_list.append(item.strip())

        dst_list = myutility.filter_unique_item(src_list)

        expected = 5
        msg_format = 'expecte {0}, but {1}'
        self.assertEqual(expected, len(dst_list),
                         msg_format.format(expected, len(dst_list)))
Beispiel #9
0
    def test_detect_file_enc(self):
        test_name = r'for_test.txt'
        file_name = myfile.get_real_dir(__modpath__) + os.sep + test_name
        enc_result = myfile.detect_file_enc(file_name)

        expecte = 'GB2312'
        msg_format = 'expecte {0}, but {1}'
        self.assertEqual(expecte, enc_result['encoding'], msg_format.format(expecte, enc_result['encoding']))

        test_name = r'alias_example.txt'
        file_name = myfile.get_real_dir(__modpath__) + os.sep + test_name
        enc_result = myfile.detect_file_enc(file_name)

        expecte = 'utf-8'
        msg_format = 'expecte {0}, but {1}'
        self.assertEqual(expecte, enc_result['encoding'], msg_format.format(expecte, enc_result['encoding']))

        test_name = r'utf_8_sig.txt'
        file_name = myfile.get_real_dir(__modpath__) + os.sep + test_name
        enc_result = myfile.detect_file_enc(file_name)

        expecte = 'utf-8-sig'
        msg_format = 'expecte {0}, but {1}'
        self.assertEqual(expecte, enc_result['encoding'], msg_format.format(expecte, enc_result['encoding']))
Beispiel #10
0
    def test_get_dict_from_file(self):
        alias_file = 'alias_example.txt'
        file_name = myfile.get_real_dir(__modpath__) + os.sep + alias_file
        dict_ = myfile.get_dict_from_file(file_name)
        key = 'BTV文艺'
        value = '北京文艺'
        msg_format = 'expecte {0}, but {1}'
        self.assertEqual(dict_[key], value, msg_format.format(value, dict_[key]))

        key = 'BTV科教'
        value = '北京科教'
        msg_format = 'expecte {0}, but {1}'
        self.assertEqual(dict_[key], value, msg_format.format(value, dict_[key]))

        key = 'what'
        msg_format = 'expecte {0}, but {1}'
        self.assertFalse(key in dict_, msg_format.format(False, True))

        key = 'BTV科教'
        msg_format = 'expecte {0}, but {1}'
        self.assertTrue(key in dict_, msg_format.format(False, True))
Beispiel #11
0
def test_read_valid_string_list_from_file():
    test_name = r'test_valid_string_list.txt'
    file_name = myfile.get_real_dir(__modpath__) + os.sep + test_name
    valid_list = myfile.read_valid_string_list_from_file(file_name)
    pprint.pprint(valid_list)