From 04c4064c68a04954c541bf122bcd913fd23ff2da Mon Sep 17 00:00:00 2001
From: 03 <1930154319@qq.com>
Date: Mon, 18 Mar 2024 13:21:46 +0800
Subject: [PATCH 1/7] Fix bug 553
---
app/templates/mainpage_post.html | 2 +-
app/wordfreqCMD.py | 4 +++-
2 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/app/templates/mainpage_post.html b/app/templates/mainpage_post.html
index 7357457..5df7dd5 100644
--- a/app/templates/mainpage_post.html
+++ b/app/templates/mainpage_post.html
@@ -2,7 +2,7 @@
- Title
+ 单词词频
{{ yml['header'] | safe }}
{% if yml['css']['item'] %}
diff --git a/app/wordfreqCMD.py b/app/wordfreqCMD.py
index dcee74e..dfdde2e 100644
--- a/app/wordfreqCMD.py
+++ b/app/wordfreqCMD.py
@@ -4,6 +4,7 @@
###########################################################################
import collections
+import html
import string
import operator
import os, sys # 引入模块sys,因为我要用里面的sys.argv列表中的信息来读取命令行参数。
@@ -39,7 +40,8 @@ def file2str(fname):#文件转字符
def remove_punctuation(s): # 这里是s是形参 (parameter)。函数被调用时才给s赋值。
- special_characters = '\_©~<=>+/[]*&$%^@.,?!:;#()"“”—‘’{}|' # 把里面的字符都去掉
+ special_characters = '\_©~<=>+/[]*&$%^@.,?!:;#()"“”—‘’{}|,。?!¥……()、《》:;·' # 把里面的字符都去掉
+ s = html.unescape(s)
for c in special_characters:
s = s.replace(c, ' ') # 防止出现把 apple,apple 移掉逗号后变成 appleapple 情况
s = s.replace('--', ' ')
--
2.17.1
From b8f2919959e1a31979df4476a188517896870e26 Mon Sep 17 00:00:00 2001
From: 03 <1930154319@qq.com>
Date: Mon, 25 Mar 2024 10:15:11 +0800
Subject: [PATCH 2/7] Fix bug 553
---
app/wordfreqCMD.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/app/wordfreqCMD.py b/app/wordfreqCMD.py
index dfdde2e..4cf550e 100644
--- a/app/wordfreqCMD.py
+++ b/app/wordfreqCMD.py
@@ -41,7 +41,7 @@ def file2str(fname):#文件转字符
def remove_punctuation(s): # 这里是s是形参 (parameter)。函数被调用时才给s赋值。
special_characters = '\_©~<=>+/[]*&$%^@.,?!:;#()"“”—‘’{}|,。?!¥……()、《》:;·' # 把里面的字符都去掉
- s = html.unescape(s)
+ s = html.unescape(s) # 将HTML实体转换为对应的字符,比如<会被识别为小于号
for c in special_characters:
s = s.replace(c, ' ') # 防止出现把 apple,apple 移掉逗号后变成 appleapple 情况
s = s.replace('--', ' ')
--
2.17.1
From b7fe68c54d6bfc297cfc2d99bb367c14e147883b Mon Sep 17 00:00:00 2001
From: 03 <1930154319@qq.com>
Date: Mon, 8 Apr 2024 16:37:15 +0800
Subject: [PATCH 3/7] test_bug553
---
app/test/test_bug553_LinShan.py | 81 +++++++++++++++++++++++++++++++++
app/test/test_file.json | 30 ++++++++++++
app/wordfreqCMD.py | 2 +-
3 files changed, 112 insertions(+), 1 deletion(-)
create mode 100644 app/test/test_bug553_LinShan.py
create mode 100644 app/test/test_file.json
diff --git a/app/test/test_bug553_LinShan.py b/app/test/test_bug553_LinShan.py
new file mode 100644
index 0000000..8ba25f1
--- /dev/null
+++ b/app/test/test_bug553_LinShan.py
@@ -0,0 +1,81 @@
+# -*- coding: utf-8 -*-
+# Run the docker image using the following command:
+# docker run -d -p 4444:4444 selenium/standalone-chrome
+from selenium import webdriver
+from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
+from selenium.webdriver.support import expected_conditions as EC
+from selenium import webdriver
+from selenium.webdriver.support.wait import WebDriverWait
+from selenium.webdriver.common.by import By
+from webdriver_manager.chrome import ChromeDriverManager
+from selenium.webdriver.common.keys import Keys
+import logging
+import json
+import os
+import time
+
+# driver = webdriver.Remote('http://localhost:4444/wd/hub', DesiredCapabilities.FIREFOX)
+# HOME_PAGE = 'http://121.4.94.30:91/'
+
+
+# 我使用的是Chrome浏览器,所以我又通过安装webdriver-manager插件来配置浏览器的驱动
+# 我通过 'pip install webdriver-manager==4.00' 命令安装webdriver-manager,并且设置其版本为4.00
+driver = webdriver.Chrome(ChromeDriverManager().install())
+HOME_PAGE = 'http://127.0.0.1:5000/'
+driver.implicitly_wait(10)
+
+
+# 加载存有测试数据的json文件
+def load_json_file(file_path):
+ # 获取当前所在文件的目录
+ dir_path = os.path.dirname(os.path.abspath(__file__))
+ # 将目录路径和文件名进行拼接,获取最终的文件路径
+ file_path = dir_path+"\\"+file_path
+ # 加载文件
+ with open(file_path,encoding='utf-8') as f:
+ data = json.load(f)
+ return data
+
+
+def test_bug553_LinShan():
+ try:
+ # 打开对应地址的网页
+ driver.get(HOME_PAGE)
+
+ # 浏览器最大窗口化
+ driver.maximize_window()
+
+ # 判断网页源代码中是否有English Pal -文字
+ assert 'English Pal -' in driver.page_source
+
+ # 获取json格式的测试数据
+ words = load_json_file("test_file.json")
+
+ # 遍历测试的数据
+ for word in words:
+ # 将测试的数据输入到主页的textarea里
+ driver.find_element_by_xpath("//textarea[@name='content']").send_keys(Keys.CONTROL, "a")
+ driver.find_element_by_xpath("//textarea[@name='content']").send_keys(word['key'])
+ time.sleep(2)
+
+ # 点击按钮获取单词
+ driver.find_element_by_xpath("//input[@value='get文章中的词频']").click()
+ time.sleep(2)
+
+ # 获取筛选后的单词
+ get_words = driver.find_elements_by_xpath("//p/a")
+
+ # 遍历获取到的单词,并判断单词与预期的相同
+ for w in get_words:
+ # 判断单词是否在预期结果中
+ assert w.text in word['value']
+
+ # 返回上一页网页
+ driver.find_element_by_xpath("//input[@value='确定并返回']").click()
+ time.sleep(2)
+ except Exception as e:
+ # 输出异常信息
+ logging.error(e)
+ finally:
+ # 关闭浏览器
+ driver.quit()
\ No newline at end of file
diff --git a/app/test/test_file.json b/app/test/test_file.json
new file mode 100644
index 0000000..5bd2499
--- /dev/null
+++ b/app/test/test_file.json
@@ -0,0 +1,30 @@
+[
+ {
+ "key":"‘test1’",
+ "value": ["test1"]
+ },
+ {
+ "key":"'test2'",
+ "value": ["test2"]
+ },
+ {
+ "key":"“test3”",
+ "value": ["test3"]
+ },
+ {
+ "key":"it's",
+ "value": ["it's"]
+ },
+ {
+ "key":"hello,I'm linshan",
+ "value": ["hello","i'm","linshan"]
+ },
+ {
+ "key":"Happy New Year!?",
+ "value": ["happy","new","year"]
+ },
+ {
+ "key":"My favorite book is 《Harry Potter》。",
+ "value":["potter","harry","my","favorite","book","is"]
+ }
+]
\ No newline at end of file
diff --git a/app/wordfreqCMD.py b/app/wordfreqCMD.py
index 4cf550e..feeafbd 100644
--- a/app/wordfreqCMD.py
+++ b/app/wordfreqCMD.py
@@ -106,7 +106,7 @@ if __name__ == '__main__':
print('%s\t%d\t%s' % (x[0], x[1], youdao_link(x[0])))#函数导出
# 把频率的结果放result.html中
- make_html_page(sort_in_descending_order(L), 'result.html')
+ make_html_page(sort_in_descending_order(L), 'result.html')
print('\nHistory:\n')
if os.path.exists('frequency.p'):
--
2.17.1
From 768c81828de6df2ac10f6be06ba0ffc4531c6516 Mon Sep 17 00:00:00 2001
From: 03 <1930154319@qq.com>
Date: Tue, 16 Apr 2024 08:46:16 +0800
Subject: [PATCH 4/7] Fix Bug553
---
app/test/test_bug553_LinShan.py | 61 +++++++++++++--------------------
1 file changed, 23 insertions(+), 38 deletions(-)
diff --git a/app/test/test_bug553_LinShan.py b/app/test/test_bug553_LinShan.py
index 8ba25f1..393e82d 100644
--- a/app/test/test_bug553_LinShan.py
+++ b/app/test/test_bug553_LinShan.py
@@ -10,9 +10,8 @@ from selenium.webdriver.common.by import By
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.keys import Keys
import logging
-import json
-import os
import time
+import pytest
# driver = webdriver.Remote('http://localhost:4444/wd/hub', DesiredCapabilities.FIREFOX)
# HOME_PAGE = 'http://121.4.94.30:91/'
@@ -25,19 +24,9 @@ HOME_PAGE = 'http://127.0.0.1:5000/'
driver.implicitly_wait(10)
-# 加载存有测试数据的json文件
-def load_json_file(file_path):
- # 获取当前所在文件的目录
- dir_path = os.path.dirname(os.path.abspath(__file__))
- # 将目录路径和文件名进行拼接,获取最终的文件路径
- file_path = dir_path+"\\"+file_path
- # 加载文件
- with open(file_path,encoding='utf-8') as f:
- data = json.load(f)
- return data
-
-
-def test_bug553_LinShan():
+@pytest.mark.parametrize("test_input",("‘test1’","'test2'","“test3”","it's","hello,I'm linshan","Happy New Year!?","My favorite book is 《Harry Potter》。"))
+@pytest.mark.parametrize("expected",(["test1"],["test2"],["test3"],["it's"],["hello","i'm","linshan"],["happy","new","year"],["potter","harry","my","favorite","book","is"]))
+def test_bug553_LinShan(test_input,expected):
try:
# 打开对应地址的网页
driver.get(HOME_PAGE)
@@ -48,34 +37,30 @@ def test_bug553_LinShan():
# 判断网页源代码中是否有English Pal -文字
assert 'English Pal -' in driver.page_source
- # 获取json格式的测试数据
- words = load_json_file("test_file.json")
+ # 将测试的数据输入到主页的textarea里
+ driver.find_element_by_xpath("//textarea[@name='content']").send_keys(Keys.CONTROL, "a")
+ driver.find_element_by_xpath("//textarea[@name='content']").send_keys(test_input)
+ time.sleep(2)
- # 遍历测试的数据
+ # 点击按钮获取单词
+ driver.find_element_by_xpath("//input[@value='get文章中的词频']").click()
+ time.sleep(2)
+
+ # 获取筛选后的单词
+ words = driver.find_elements_by_xpath("//p/a")
+
+ # 遍历获取到的单词,并判断单词与预期的相同
for word in words:
- # 将测试的数据输入到主页的textarea里
- driver.find_element_by_xpath("//textarea[@name='content']").send_keys(Keys.CONTROL, "a")
- driver.find_element_by_xpath("//textarea[@name='content']").send_keys(word['key'])
- time.sleep(2)
-
- # 点击按钮获取单词
- driver.find_element_by_xpath("//input[@value='get文章中的词频']").click()
- time.sleep(2)
-
- # 获取筛选后的单词
- get_words = driver.find_elements_by_xpath("//p/a")
-
- # 遍历获取到的单词,并判断单词与预期的相同
- for w in get_words:
- # 判断单词是否在预期结果中
- assert w.text in word['value']
+ # 判断单词是否在预期结果中
+ assert word.text in expected
- # 返回上一页网页
- driver.find_element_by_xpath("//input[@value='确定并返回']").click()
- time.sleep(2)
+ # 返回上一页网页
+ driver.find_element_by_xpath("//input[@value='确定并返回']").click()
+ time.sleep(2)
+
except Exception as e:
# 输出异常信息
logging.error(e)
- finally:
# 关闭浏览器
+ finally:
driver.quit()
\ No newline at end of file
--
2.17.1
From 4ea6d9aeed2154057eb16c6ea36cb60b9272e638 Mon Sep 17 00:00:00 2001
From: 03 <1930154319@qq.com>
Date: Tue, 16 Apr 2024 08:48:55 +0800
Subject: [PATCH 5/7] Fix Bug553
---
app/test/test_file.json | 30 ------------------------------
1 file changed, 30 deletions(-)
delete mode 100644 app/test/test_file.json
diff --git a/app/test/test_file.json b/app/test/test_file.json
deleted file mode 100644
index 5bd2499..0000000
--- a/app/test/test_file.json
+++ /dev/null
@@ -1,30 +0,0 @@
-[
- {
- "key":"‘test1’",
- "value": ["test1"]
- },
- {
- "key":"'test2'",
- "value": ["test2"]
- },
- {
- "key":"“test3”",
- "value": ["test3"]
- },
- {
- "key":"it's",
- "value": ["it's"]
- },
- {
- "key":"hello,I'm linshan",
- "value": ["hello","i'm","linshan"]
- },
- {
- "key":"Happy New Year!?",
- "value": ["happy","new","year"]
- },
- {
- "key":"My favorite book is 《Harry Potter》。",
- "value":["potter","harry","my","favorite","book","is"]
- }
-]
\ No newline at end of file
--
2.17.1
From 9aa718b2368a24c2fc17d9e99f33f9d806072fce Mon Sep 17 00:00:00 2001
From: Lan Hui <1348141770@qq.com>
Date: Thu, 18 Apr 2024 20:06:02 +0800
Subject: [PATCH 6/7] Simplify the test code, use the Edge WebDriver
---
app/test/test_bug553_LinShan.py | 37 +++++++++++++--------------------
1 file changed, 14 insertions(+), 23 deletions(-)
diff --git a/app/test/test_bug553_LinShan.py b/app/test/test_bug553_LinShan.py
index 393e82d..d463c2b 100644
--- a/app/test/test_bug553_LinShan.py
+++ b/app/test/test_bug553_LinShan.py
@@ -1,35 +1,26 @@
-# -*- coding: utf-8 -*-
-# Run the docker image using the following command:
-# docker run -d -p 4444:4444 selenium/standalone-chrome
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.support import expected_conditions as EC
from selenium import webdriver
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.by import By
-from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.keys import Keys
import logging
import time
import pytest
-# driver = webdriver.Remote('http://localhost:4444/wd/hub', DesiredCapabilities.FIREFOX)
-# HOME_PAGE = 'http://121.4.94.30:91/'
-
-
-# 我使用的是Chrome浏览器,所以我又通过安装webdriver-manager插件来配置浏览器的驱动
-# 我通过 'pip install webdriver-manager==4.00' 命令安装webdriver-manager,并且设置其版本为4.00
-driver = webdriver.Chrome(ChromeDriverManager().install())
-HOME_PAGE = 'http://127.0.0.1:5000/'
-driver.implicitly_wait(10)
-
-
-@pytest.mark.parametrize("test_input",("‘test1’","'test2'","“test3”","it's","hello,I'm linshan","Happy New Year!?","My favorite book is 《Harry Potter》。"))
-@pytest.mark.parametrize("expected",(["test1"],["test2"],["test3"],["it's"],["hello","i'm","linshan"],["happy","new","year"],["potter","harry","my","favorite","book","is"]))
-def test_bug553_LinShan(test_input,expected):
+@pytest.mark.parametrize("test_input,expected",
+ [("‘test1’", "test1"),
+ ("'test2'", "test2"),
+ ("“test3”", "test3"),
+ ("it's", "it's"),
+ ("hello,I'm linshan", ["hello","i'm","linshan"]),
+ ("Happy New Year!?", ["happy","new","year"]),
+ ("My favorite book is 《Harry Potter》。", ["potter","harry","my","favorite","book","is"])])
+def test_bug553_LinShan(test_input,expected, driver, URL):
try:
# 打开对应地址的网页
- driver.get(HOME_PAGE)
+ driver.get(URL)
# 浏览器最大窗口化
driver.maximize_window()
@@ -40,11 +31,11 @@ def test_bug553_LinShan(test_input,expected):
# 将测试的数据输入到主页的textarea里
driver.find_element_by_xpath("//textarea[@name='content']").send_keys(Keys.CONTROL, "a")
driver.find_element_by_xpath("//textarea[@name='content']").send_keys(test_input)
- time.sleep(2)
+ time.sleep(1)
# 点击按钮获取单词
driver.find_element_by_xpath("//input[@value='get文章中的词频']").click()
- time.sleep(2)
+ time.sleep(1)
# 获取筛选后的单词
words = driver.find_elements_by_xpath("//p/a")
@@ -56,11 +47,11 @@ def test_bug553_LinShan(test_input,expected):
# 返回上一页网页
driver.find_element_by_xpath("//input[@value='确定并返回']").click()
- time.sleep(2)
+ time.sleep(0.1)
except Exception as e:
# 输出异常信息
logging.error(e)
# 关闭浏览器
finally:
- driver.quit()
\ No newline at end of file
+ driver.quit()
--
2.17.1
From 2500fa5fc8bedb0be731baf1b21b364ef06ed830 Mon Sep 17 00:00:00 2001
From: 03 <1930154319@qq.com>
Date: Mon, 22 Apr 2024 12:46:31 +0800
Subject: [PATCH 7/7] Fix bug553
---
app/test/test_bug553_LinShan.py | 1 +
1 file changed, 1 insertion(+)
diff --git a/app/test/test_bug553_LinShan.py b/app/test/test_bug553_LinShan.py
index 393e82d..74a0019 100644
--- a/app/test/test_bug553_LinShan.py
+++ b/app/test/test_bug553_LinShan.py
@@ -62,5 +62,6 @@ def test_bug553_LinShan(test_input,expected):
# 输出异常信息
logging.error(e)
# 关闭浏览器
+ driver.quit()
finally:
driver.quit()
\ No newline at end of file
--
2.17.1