From 297731f5f2e71827cc9b5dcdb75d5288762a0617 Mon Sep 17 00:00:00 2001 From: zhenwei-li Date: Wed, 19 Aug 2020 14:38:52 +0800 Subject: [PATCH 01/16] the README upgrade --- README0.md | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ doc/README0.md | 35 +++++++++++++++++++++++++++++++++++ doc/readMe.md | 29 ----------------------------- readMe.md | 44 -------------------------------------------- 4 files changed, 85 insertions(+), 73 deletions(-) create mode 100644 README0.md create mode 100644 doc/README0.md delete mode 100644 doc/readMe.md delete mode 100644 readMe.md diff --git a/README0.md b/README0.md new file mode 100644 index 0000000..c3b42d4 --- /dev/null +++ b/README0.md @@ -0,0 +1,50 @@ + +# Python-DeMo + +Python DeMo + +- [一. 构建`venv`环境](#一-构建venv环境) + - [1.1 venv2](#11-venv2) + - [1.1.1 venv2 for mac](#111-venv2-for-mac) + - [1.1.2 venv2 for windows](#112-venv2-for-windows) + - [1.2 venv3](#12-venv3) + - [1.2.1 venv3 for mac](#121-venv3-for-mac) + - [1.2.2 venv3 for windows](#122-venv3-for-windows) + +## 一. 构建`venv`环境 + +### 1.1 venv2 + +#### 1.1.1 venv2 for mac + +```bash +virtualenv -p /usr/local/bin/python2 --no-site-packages venv2 +``` + +#### 1.1.2 venv2 for windows + +```bash +python2 -m virtualenv -p C:\Python\Python27\python2.exe venv2 + +或 + +python2 -m virtualenv -p C:\Python\Python27\python2.exe venv2 > venv2.log +``` + +### 1.2 venv3 + +#### 1.2.1 venv3 for mac + +```bash +virtualenv -p /usr/local/bin/python3 --no-site-packages venv +``` + +#### 1.2.2 venv3 for windows + +```bash +python3 -m virtualenv -p C:\Python\Python38\python3.exe venv + +或 + +python3 -m virtualenv -p C:\Python\Python38\python3.exe venv > venv.log +``` diff --git a/doc/README0.md b/doc/README0.md new file mode 100644 index 0000000..1026f19 --- /dev/null +++ b/doc/README0.md @@ -0,0 +1,35 @@ + +# 文档 + +- [一. 查看函数命令](#一-查看函数命令) + - [1.1 Mac/Linux 环境查看函数](#11-maclinux-环境查看函数) + - [1.2. Windows 环境查看函数](#12-windows-环境查看函数) + - [1.3. 阅读源码命令](#13-阅读源码命令) + +## 一. 查看函数命令 + +### 1.1 Mac/Linux 环境查看函数 + +```python +pydoc function // 具体参考函数 +``` + +### 1.2. Windows 环境查看函数 + +```python +python -m pydoc function // 具体参考函数 +``` + +### 1.3. 阅读源码命令 + +阅读命令: + +```python +python3 -m pydoc -p 8081 +``` + +自己封装了一个脚本,调用命令: + +```python +source ./doc/pydoc.py +``` diff --git a/doc/readMe.md b/doc/readMe.md deleted file mode 100644 index 2722fd6..0000000 --- a/doc/readMe.md +++ /dev/null @@ -1,29 +0,0 @@ - -## 查看函数命令 - -### 1. Mac/Linux 环境查看函数 - -``` -pydoc function // 具体参考函数 -``` - -### 2. Windows 环境查看函数 - -``` -python -m pydoc function // 具体参考函数 -``` - -### 3. 阅读源码命令 - -阅读命令: - -``` -python3 -m pydoc -p 8081 -``` - -自己封装了一个脚本,调用命令: - -``` -source ./doc/pydoc.py -``` - diff --git a/readMe.md b/readMe.md deleted file mode 100644 index bc47b12..0000000 --- a/readMe.md +++ /dev/null @@ -1,44 +0,0 @@ - -# Python-DeMo - -Python DeMo - - - -## 构建`venv`环境 - -### venv2 - -#### 1. venv2 for mac - -``` -virtualenv -p /usr/local/bin/python2 --no-site-packages venv2 -``` - -#### 2. venv2 for windows - -``` -python2 -m virtualenv -p C:\Python\Python27\python2.exe venv2 - -或 - -python2 -m virtualenv -p C:\Python\Python27\python2.exe venv2 > venv2.log -``` - -### venv3 - -#### 1. venv3 for mac - -``` -virtualenv -p /usr/local/bin/python3 --no-site-packages venv -``` - -#### 2. venv3 for windows - -``` -python3 -m virtualenv -p C:\Python\Python38\python3.exe venv - -或 - -python3 -m virtualenv -p C:\Python\Python38\python3.exe venv > venv.log -``` From a3603020efa9e238936dee05eb7ab268ead968c7 Mon Sep 17 00:00:00 2001 From: zhenwei-li Date: Wed, 19 Aug 2020 14:39:23 +0800 Subject: [PATCH 02/16] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README0.md => README.md | 0 doc/{README0.md => README.md} | 0 doc/source.log | 6 ++++++ 3 files changed, 6 insertions(+) rename README0.md => README.md (100%) rename doc/{README0.md => README.md} (100%) create mode 100755 doc/source.log diff --git a/README0.md b/README.md similarity index 100% rename from README0.md rename to README.md diff --git a/doc/README0.md b/doc/README.md similarity index 100% rename from doc/README0.md rename to doc/README.md diff --git a/doc/source.log b/doc/source.log new file mode 100755 index 0000000..495cdd9 --- /dev/null +++ b/doc/source.log @@ -0,0 +1,6 @@ +尝试去一些网站读源码: + +- https://github.com/ +- https://launchpad.net/ +- https://koders.com/ +- https://bitbucket.org/ From aae62bcd433645dca38384e4dc358051dc822434 Mon Sep 17 00:00:00 2001 From: zhenwei-li Date: Tue, 25 Aug 2020 16:11:16 +0800 Subject: [PATCH 03/16] the settings upgrade --- .vscode/settings.json | 53 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100755 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100755 index 0000000..5ebae67 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,53 @@ +{ + "python.pythonPath": "venv2/bin/python", + "python.formatting.provider": "yapf", + "python.linting.pylintEnabled": false, + "python.linting.flake8Enabled": true, + "python.linting.flake8Args": ["--max-line-length=250"], + "editor.tabSize": 4, + "editor.detectIndentation": false, + "debug.toolBarLocation": "docked", + "editor.suggestSelection": "first", + "editor.fontSize": 14, + "editor.formatOnSave": true, + "editor.formatOnType": true, + "editor.wordWrapColumn": 250, + "editor.columnSelection": false, + "editor.mouseWheelZoom": true, + "explorer.confirmDelete": false, + "editor.renderWhitespace": "all", + "editor.renderControlCharacters": true, + "editor.suggest.shareSuggestSelections": true, + "editor.renderIndentGuides": false, + "debug.console.fontSize": 14, + "git.autofetch": true, + "[json]": { + "editor.defaultFormatter": "HookyQR.beautify" + }, + "[jsonc]": { + "editor.defaultFormatter": "HookyQR.beautify" + }, + "terminal.integrated.fontSize": 14, + "markdown.extension.toc.githubCompatibility": true, + "markdownlint.config": { + "MD033": false + }, + "markdown.extension.katex.macros": {}, + "markdown.extension.toc.levels": "2..6", + "terminal.integrated.copyOnSelection": true, + // "files.autoSave": "afterDelay", + "files.insertFinalNewline": true, + "files.autoGuessEncoding": true, + "files.exclude": { + "**/.git": true, + "**/.svn": true, + "**/.hg": true, + "**/CVS": true, + "**/.DS_Store": true, + "**/*.pyc": true + }, + "workbench.iconTheme": "vscode-icons", + "workbench.editor.enablePreview": true, + "workbench.editor.enablePreviewFromQuickOpen": true, + "window.zoomLevel": 0, +} From ac320b407e52c21376bf419124af6ec24e081119 Mon Sep 17 00:00:00 2001 From: zhenwei-li Date: Mon, 31 Aug 2020 17:23:04 +0800 Subject: [PATCH 04/16] the source upgrade --- .vscode/settings.json | 39 ++++++++++++++++++++++++++++------- doc/{source.log => source.md} | 4 ++++ 2 files changed, 36 insertions(+), 7 deletions(-) rename doc/{source.log => source.md} (63%) diff --git a/.vscode/settings.json b/.vscode/settings.json index 5ebae67..aee6b86 100755 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,12 +1,7 @@ { - "python.pythonPath": "venv2/bin/python", - "python.formatting.provider": "yapf", - "python.linting.pylintEnabled": false, - "python.linting.flake8Enabled": true, - "python.linting.flake8Args": ["--max-line-length=250"], "editor.tabSize": 4, "editor.detectIndentation": false, - "debug.toolBarLocation": "docked", + // "debug.toolBarLocation": "docked", "editor.suggestSelection": "first", "editor.fontSize": 14, "editor.formatOnSave": true, @@ -30,7 +25,8 @@ "terminal.integrated.fontSize": 14, "markdown.extension.toc.githubCompatibility": true, "markdownlint.config": { - "MD033": false + "MD033": false, + "MD034": false, }, "markdown.extension.katex.macros": {}, "markdown.extension.toc.levels": "2..6", @@ -46,6 +42,35 @@ "**/.DS_Store": true, "**/*.pyc": true }, + "python.analysis.logLevel": "Trace", + "python.analysis.watchSearchPaths": true, + "python.autoComplete.extraPaths": [ + "./src", + "./mock", + "./test", + "./venv2/bin", + "./venv2/Lib/python2.7/site-packages", + // "./venv/bin", + // "./venv/Lib/python3.7/site-packages", + ], + "python.pythonPath": "venv2/bin/python", + "python.formatting.provider": "yapf", + "python.languageServer": "Microsoft", + "python.linting.pylintEnabled": false, + "python.linting.flake8Enabled": true, + "python.linting.flake8Args": ["--max-line-length=250"], + "python.testing.unittestArgs": [ + "-v", + "-s", + "./test", + "-p", + "test_*.py" + ], + "python.testing.autoTestDiscoverOnSaveEnabled": true, + "python.testing.cwd": "${workspaceFolder}", + "python.testing.nosetestsEnabled": false, + "python.testing.pytestEnabled": false, + "python.testing.unittestEnabled": true, "workbench.iconTheme": "vscode-icons", "workbench.editor.enablePreview": true, "workbench.editor.enablePreviewFromQuickOpen": true, diff --git a/doc/source.log b/doc/source.md similarity index 63% rename from doc/source.log rename to doc/source.md index 495cdd9..94ab81b 100755 --- a/doc/source.log +++ b/doc/source.md @@ -1,6 +1,10 @@ +# 阅读 + 尝试去一些网站读源码: - https://github.com/ - https://launchpad.net/ - https://koders.com/ - https://bitbucket.org/ +- https://www.python.org/dev/peps/ +- https://stackoverflow.com/ From 91a9a61be8aaf6f8e866cc6b9236bc746b47aaea Mon Sep 17 00:00:00 2001 From: zhenwei-li Date: Tue, 1 Sep 2020 15:44:39 +0800 Subject: [PATCH 05/16] =?UTF-8?q?=E6=B5=8B=E8=AF=95map=20=E7=94=A8?= =?UTF-8?q?=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/function/test_map.py | 51 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/function/test_map.py diff --git a/src/function/test_map.py b/src/function/test_map.py new file mode 100644 index 0000000..54d7d15 --- /dev/null +++ b/src/function/test_map.py @@ -0,0 +1,51 @@ +# -*- coding:utf-8 -*- + + +def test_map(): + tags = { + 'v0.0.2': { + 'stamp': 1576053555, + 'date': '2019-12-11', + 'authors': { + 'DovSnier': 3 + }, + 'hash': 'b76da094137669d3eb3edc985391366bc2bb93b9', + 'commits': 22 + }, + 'v0.0.3': { + 'stamp': 1576053555, + 'date': '2019-12-21', + 'authors': { + 'DovSnier': 3 + }, + 'hash': 'b76da094137669d3eb3edc985391366bc2bb93b9', + 'commits': 23 + }, + 'v0.0.1': { + 'stamp': 1576053555, + 'date': '2019-12-1', + 'authors': { + 'DovSnier': 3 + }, + 'hash': 'b76da094137669d3eb3edc985391366bc2bb93b9', + 'commits': 21 + } + } + # lambda + list_o = map(lambda el: (el[1]['date'], el[0]), tags.items()) + + # function + # list_o = map(test_tuple, tags.items()) + + print list_o + tags_sorted_by_date_desc = map(lambda el: el[1], reversed(sorted(list_o))) + print tags_sorted_by_date_desc + + +def test_tuple(element): + return (element[1]['date'], element[0]) + + +if __name__ == "__main__": + '''主函数入口''' + test_map() From 21e38755b53f224730328be1f43dd5ca25d1af7e Mon Sep 17 00:00:00 2001 From: zhenwei-li Date: Wed, 2 Sep 2020 16:49:48 +0800 Subject: [PATCH 06/16] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E5=AD=97=E5=85=B8?= =?UTF-8?q?=E6=8E=92=E5=BA=8F=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/function/test_dict_sort.py | 123 +++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 src/function/test_dict_sort.py diff --git a/src/function/test_dict_sort.py b/src/function/test_dict_sort.py new file mode 100644 index 0000000..35db356 --- /dev/null +++ b/src/function/test_dict_sort.py @@ -0,0 +1,123 @@ +# -*- coding:utf-8 -*- + +import collections +import json +# import pprint + +tags = { + 'a': 2, + 'v0.0.2': { + 'stamp': 1576053555, + 'date': '2019-12-11', + 'authors': { + 'DovSnier': 3 + }, + 'hash': 'b76da094137669d3eb3edc985391366bc2bb93b9', + 'commits': 22 + }, + 'bc': '32', + 'ac': {}, + 'v0.0.3': { + 'stamp': 1576053555, + 'date': '2019-12-21', + 'authors': { + 'DovSnier': 3 + }, + 'hash': 'b76da094137669d3eb3edc985391366bc2bb93b9', + 'commits': 23 + }, + 'v0.0.1': { + 'stamp': 1576053555, + 'date': '2019-12-1', + 'authors': { + 'DovSnier': 3 + }, + 'hash': 'b76da094137669d3eb3edc985391366bc2bb93b9', + 'commits': 21 + }, + 's': ['2020-01-09', '2020-01-10'] +} + + +def test_dict_sort_slowly(): + ''' 使用sorted 会生成新的list,导致性能下降,建议使用内置sort ''' + global tags + tags_tuple_list = sorted(tags.items()) + # tags_tuple_list = sorted(tags.items(), key=lambda element: element[1]) + print('\n') + print(tags_tuple_list) + tags.clear() + print("tags is %s" % tags) + for item in tags_tuple_list: + tags[item[0]] = item[1] + print("tags is %s" % tags) + + +def test_dict_sort(): + global tags + # print(tags.items()) + keys = tags.keys() + keys.sort() + # tuple_with_tags = [(key, tags[key]) for key in keys] + # print("%s\n%s" % (type(tuple_with_tags), tuple_with_tags)) + tags_with_sort = collections.OrderedDict() # 有序字典 + for key in keys: + # tags_with_sort.setdefault(key, tags[key]) + tags_with_sort[key] = tags[key] + tags = tags_with_sort + + # prettyPrinter = pprint.PrettyPrinter(indent=4) + # prettyPrinter.pprint(tags) + + json_list = json.dumps(tags, indent=4) + print(json_list) + + # print() + # print(tags) + + +def test_print(): + ''' + { + 'v0.0.1': + { + 'stamp': 1576053555, + 'date': '2019-12-1', + 'commits': 21, + 'hash': 'b76da094137669d3eb3edc985391366bc2bb93b9', + 'authors': + { + 'DovSnier': 3 + } + }, + 'v0.0.2': + { + 'stamp': 1576053555, + 'date': '2019-12-11', + 'commits': 22, + 'hash': 'b76da094137669d3eb3edc985391366bc2bb93b9', + 'authors': + { + 'DovSnier': 3 + } + }, + 'v0.0.3': + { + 'stamp': 1576053555, + 'date': '2019-12-21', + 'commits': 23, + 'hash': 'b76da094137669d3eb3edc985391366bc2bb93b9', + 'authors': + { + 'DovSnier': 3 + } + } + } + ''' + pass + + +if __name__ == "__main__": + '''主函数入口''' + test_dict_sort() + # test_dict_sort_slowly() From 9c1fd63789a2f0eac3d1cd75e95da7a65b15084f Mon Sep 17 00:00:00 2001 From: zhenwei-li Date: Fri, 27 Nov 2020 11:06:09 +0800 Subject: [PATCH 07/16] =?UTF-8?q?=E6=B7=BB=E5=8A=A0logging=20=E6=97=A5?= =?UTF-8?q?=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/https.py | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/src/https.py b/src/https.py index 73169bf..46fff47 100644 --- a/src/https.py +++ b/src/https.py @@ -4,12 +4,15 @@ import urllib2 import os # import shutil +import logging +import time def requests(): req_url = 'http://www.baidu.com/' - print(req_url) + # print(req_url) + logging.info('this request url is %s' % req_url) response = urllib2.urlopen(req_url) headers = response.headers @@ -44,12 +47,22 @@ def requests(): if any(headers): header_of_log = os.path.join(req_dir, 'response.header.log') file = open(header_of_log, 'w') - file.write(str(headers.dict)) + value = str(headers.dict) + logging.debug('this request headers is %s' % value) + file.write(value) file.close() body_of_log = os.path.join('out/request', 'response.body.log') file = open(body_of_log, 'w') - file.write(str(response.read())) + response_to_string = str(response.read()) + # logging.debug('this is response is %s' % response_to_string) + # + # logging.debug('this is debug message.') + # logging.info('this is info message.') + # logging.warning('this is warning message.') + # logging.error('this is error message.') + # logging.critical('this is critical message.') + file.write(response_to_string) file.close() @@ -62,5 +75,23 @@ def removeTree(dir): os.rmdir(os.path.join(root, name)) +def generateFileName(): + 'the generate out file name' + project_dir = os.path.abspath('.') + out_dir = os.path.join(project_dir, 'out') + http_dir = os.path.join(out_dir, 'http') + if not os.path.exists(http_dir): + os.makedirs(http_dir) + file_name = 'http_%s.log' % int(time.time()) + return os.path.join(http_dir, file_name) + + if __name__ == "__main__": + logging.basicConfig( + filename=generateFileName(), + filemode='a', + format='[%(asctime)s][%(levelname)8s] --- %(message)s', + # format= + # '[%(asctime)s][%(levelname)8s][%(filename)s:%(lineno)s] --- %(message)s', + level=logging.DEBUG) requests() From 1e209d1b7550b96f537e65fcfa76c5e683b9b0a1 Mon Sep 17 00:00:00 2001 From: zhenwei-li Date: Fri, 27 Nov 2020 11:18:34 +0800 Subject: [PATCH 08/16] =?UTF-8?q?=E7=A7=BB=E5=8A=A8=E7=9B=AE=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- {src => case}/Demo.py | 0 {src => case}/annotation.py | 0 {src => case}/argparse/test_argparse.py | 0 {src => case}/class/test_class_2.7.py | 0 {src => case}/class/test_class_2.x.py | 0 {src => case}/class/test_class_3.7.py | 0 {src => case}/class/test_class_3.x.py | 0 {src => case}/file/test_file.py | 0 {src => case}/function/test_dict_sort.py | 0 {src => case}/function/test_map.py | 0 {src => case}/https.py | 0 {src => case}/logging/test_loggins.py | 0 {src => case}/logging/test_thread_loggins.py | 0 {src => case}/readExcel.py | 0 {src => case}/srcFile.py | 0 {src => case}/standard_library/test_argv.py | 0 {src => case}/standard_library/test_dict.py | 0 {src => case}/standard_library/test_getopts.py | 0 {src => case}/standard_library/test_lock.py | 0 {src => case}/standard_library/test_os_fork.py | 0 {src => case}/standard_library/test_popen.py | 0 {src => case}/standard_library/test_popen_question.py | 0 {src => case}/standard_library/test_queue.py | 0 {src => case}/standard_library/test_send_smtp.py | 0 {src => case}/standard_library/test_send_smtp_ssl.py | 0 {src => case}/standard_library/test_sendmail.py | 0 {src => case}/standard_library/test_thread.py | 0 {src => case}/standard_library/test_threading.py | 0 28 files changed, 0 insertions(+), 0 deletions(-) rename {src => case}/Demo.py (100%) rename {src => case}/annotation.py (100%) rename {src => case}/argparse/test_argparse.py (100%) rename {src => case}/class/test_class_2.7.py (100%) rename {src => case}/class/test_class_2.x.py (100%) rename {src => case}/class/test_class_3.7.py (100%) rename {src => case}/class/test_class_3.x.py (100%) rename {src => case}/file/test_file.py (100%) rename {src => case}/function/test_dict_sort.py (100%) rename {src => case}/function/test_map.py (100%) rename {src => case}/https.py (100%) rename {src => case}/logging/test_loggins.py (100%) rename {src => case}/logging/test_thread_loggins.py (100%) rename {src => case}/readExcel.py (100%) rename {src => case}/srcFile.py (100%) rename {src => case}/standard_library/test_argv.py (100%) rename {src => case}/standard_library/test_dict.py (100%) rename {src => case}/standard_library/test_getopts.py (100%) rename {src => case}/standard_library/test_lock.py (100%) rename {src => case}/standard_library/test_os_fork.py (100%) rename {src => case}/standard_library/test_popen.py (100%) rename {src => case}/standard_library/test_popen_question.py (100%) rename {src => case}/standard_library/test_queue.py (100%) rename {src => case}/standard_library/test_send_smtp.py (100%) rename {src => case}/standard_library/test_send_smtp_ssl.py (100%) rename {src => case}/standard_library/test_sendmail.py (100%) rename {src => case}/standard_library/test_thread.py (100%) rename {src => case}/standard_library/test_threading.py (100%) diff --git a/src/Demo.py b/case/Demo.py similarity index 100% rename from src/Demo.py rename to case/Demo.py diff --git a/src/annotation.py b/case/annotation.py similarity index 100% rename from src/annotation.py rename to case/annotation.py diff --git a/src/argparse/test_argparse.py b/case/argparse/test_argparse.py similarity index 100% rename from src/argparse/test_argparse.py rename to case/argparse/test_argparse.py diff --git a/src/class/test_class_2.7.py b/case/class/test_class_2.7.py similarity index 100% rename from src/class/test_class_2.7.py rename to case/class/test_class_2.7.py diff --git a/src/class/test_class_2.x.py b/case/class/test_class_2.x.py similarity index 100% rename from src/class/test_class_2.x.py rename to case/class/test_class_2.x.py diff --git a/src/class/test_class_3.7.py b/case/class/test_class_3.7.py similarity index 100% rename from src/class/test_class_3.7.py rename to case/class/test_class_3.7.py diff --git a/src/class/test_class_3.x.py b/case/class/test_class_3.x.py similarity index 100% rename from src/class/test_class_3.x.py rename to case/class/test_class_3.x.py diff --git a/src/file/test_file.py b/case/file/test_file.py similarity index 100% rename from src/file/test_file.py rename to case/file/test_file.py diff --git a/src/function/test_dict_sort.py b/case/function/test_dict_sort.py similarity index 100% rename from src/function/test_dict_sort.py rename to case/function/test_dict_sort.py diff --git a/src/function/test_map.py b/case/function/test_map.py similarity index 100% rename from src/function/test_map.py rename to case/function/test_map.py diff --git a/src/https.py b/case/https.py similarity index 100% rename from src/https.py rename to case/https.py diff --git a/src/logging/test_loggins.py b/case/logging/test_loggins.py similarity index 100% rename from src/logging/test_loggins.py rename to case/logging/test_loggins.py diff --git a/src/logging/test_thread_loggins.py b/case/logging/test_thread_loggins.py similarity index 100% rename from src/logging/test_thread_loggins.py rename to case/logging/test_thread_loggins.py diff --git a/src/readExcel.py b/case/readExcel.py similarity index 100% rename from src/readExcel.py rename to case/readExcel.py diff --git a/src/srcFile.py b/case/srcFile.py similarity index 100% rename from src/srcFile.py rename to case/srcFile.py diff --git a/src/standard_library/test_argv.py b/case/standard_library/test_argv.py similarity index 100% rename from src/standard_library/test_argv.py rename to case/standard_library/test_argv.py diff --git a/src/standard_library/test_dict.py b/case/standard_library/test_dict.py similarity index 100% rename from src/standard_library/test_dict.py rename to case/standard_library/test_dict.py diff --git a/src/standard_library/test_getopts.py b/case/standard_library/test_getopts.py similarity index 100% rename from src/standard_library/test_getopts.py rename to case/standard_library/test_getopts.py diff --git a/src/standard_library/test_lock.py b/case/standard_library/test_lock.py similarity index 100% rename from src/standard_library/test_lock.py rename to case/standard_library/test_lock.py diff --git a/src/standard_library/test_os_fork.py b/case/standard_library/test_os_fork.py similarity index 100% rename from src/standard_library/test_os_fork.py rename to case/standard_library/test_os_fork.py diff --git a/src/standard_library/test_popen.py b/case/standard_library/test_popen.py similarity index 100% rename from src/standard_library/test_popen.py rename to case/standard_library/test_popen.py diff --git a/src/standard_library/test_popen_question.py b/case/standard_library/test_popen_question.py similarity index 100% rename from src/standard_library/test_popen_question.py rename to case/standard_library/test_popen_question.py diff --git a/src/standard_library/test_queue.py b/case/standard_library/test_queue.py similarity index 100% rename from src/standard_library/test_queue.py rename to case/standard_library/test_queue.py diff --git a/src/standard_library/test_send_smtp.py b/case/standard_library/test_send_smtp.py similarity index 100% rename from src/standard_library/test_send_smtp.py rename to case/standard_library/test_send_smtp.py diff --git a/src/standard_library/test_send_smtp_ssl.py b/case/standard_library/test_send_smtp_ssl.py similarity index 100% rename from src/standard_library/test_send_smtp_ssl.py rename to case/standard_library/test_send_smtp_ssl.py diff --git a/src/standard_library/test_sendmail.py b/case/standard_library/test_sendmail.py similarity index 100% rename from src/standard_library/test_sendmail.py rename to case/standard_library/test_sendmail.py diff --git a/src/standard_library/test_thread.py b/case/standard_library/test_thread.py similarity index 100% rename from src/standard_library/test_thread.py rename to case/standard_library/test_thread.py diff --git a/src/standard_library/test_threading.py b/case/standard_library/test_threading.py similarity index 100% rename from src/standard_library/test_threading.py rename to case/standard_library/test_threading.py From 96d3a6dd348d9c2b447b0c7c3710b4d8a3e9a1fb Mon Sep 17 00:00:00 2001 From: zhenwei-li Date: Fri, 27 Nov 2020 16:01:57 +0800 Subject: [PATCH 09/16] the settings.json upgrade --- .vscode/settings.json | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.vscode/settings.json b/.vscode/settings.json index aee6b86..219ce98 100755 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -42,6 +42,13 @@ "**/.DS_Store": true, "**/*.pyc": true }, + "python.analysis.extraPaths": [ + "./src", + "./mock", + "./test", + "./venv2/bin", + "./venv2/Lib/python2.7/site-packages" + ], "python.analysis.logLevel": "Trace", "python.analysis.watchSearchPaths": true, "python.autoComplete.extraPaths": [ @@ -56,6 +63,7 @@ "python.pythonPath": "venv2/bin/python", "python.formatting.provider": "yapf", "python.languageServer": "Microsoft", + // "python.languageServer": "Pylance", "python.linting.pylintEnabled": false, "python.linting.flake8Enabled": true, "python.linting.flake8Args": ["--max-line-length=250"], From a617fac4d4875206fd261299555745a20f95c172 Mon Sep 17 00:00:00 2001 From: zhenwei-li Date: Fri, 27 Nov 2020 16:11:29 +0800 Subject: [PATCH 10/16] =?UTF-8?q?=E6=96=B0=E5=BB=BA=E7=9B=AE=E5=BD=95?= =?UTF-8?q?=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/conf/__init__.py | 1 + src/conf/common_conf.py | 17 +++++++++++++ src/dir/__init__.py | 1 + src/dir/common_dir.py | 44 ++++++++++++++++++++++++++++++++++ src/http/__init__.py | 1 + template/__init__.py | 1 + test/dir/__init__.py | 1 + test/dir/test_common_dir.py | 48 +++++++++++++++++++++++++++++++++++++ 8 files changed, 114 insertions(+) create mode 100644 src/conf/__init__.py create mode 100644 src/conf/common_conf.py create mode 100644 src/dir/__init__.py create mode 100644 src/dir/common_dir.py create mode 100644 src/http/__init__.py create mode 100644 template/__init__.py create mode 100644 test/dir/__init__.py create mode 100644 test/dir/test_common_dir.py diff --git a/src/conf/__init__.py b/src/conf/__init__.py new file mode 100644 index 0000000..380474e --- /dev/null +++ b/src/conf/__init__.py @@ -0,0 +1 @@ +# -*- coding:utf-8 -*- diff --git a/src/conf/common_conf.py b/src/conf/common_conf.py new file mode 100644 index 0000000..95fd302 --- /dev/null +++ b/src/conf/common_conf.py @@ -0,0 +1,17 @@ +# -*- coding:utf-8 -*- + +import logging +from dir.common_dir import generate_complex_file_name + + +def logging_conf(): + 'the logging conf info' + file_name = generate_complex_file_name('http', 'http') + logging.basicConfig( + filename=file_name, + filemode='a', + format='[%(asctime)s][%(levelname)8s] --- %(message)s', + # format= + # '[%(asctime)s][%(levelname)8s][%(filename)s:%(lineno)s] --- %(message)s', + level=logging.DEBUG) + logging.info('this current file is %s' % (file_name)) diff --git a/src/dir/__init__.py b/src/dir/__init__.py new file mode 100644 index 0000000..380474e --- /dev/null +++ b/src/dir/__init__.py @@ -0,0 +1 @@ +# -*- coding:utf-8 -*- diff --git a/src/dir/common_dir.py b/src/dir/common_dir.py new file mode 100644 index 0000000..cd45352 --- /dev/null +++ b/src/dir/common_dir.py @@ -0,0 +1,44 @@ +import os +import logging +import time + + +def generate_complex_file_name(output_dir_name, file_name): + 'the generate complex file name' + output_dir = mk_output_dir(output_dir_name) + name = str("%s_%s.log" % (file_name, int(time.time()))) + return os.path.join(output_dir, name) + + +def generate_file_name(output_dir_name, file_name): + 'the generate out file name' + output_dir = mk_output_dir(output_dir_name) + return os.path.join(output_dir, file_name) + + +def mk_output_dir(output_dir_name): + 'the initialize output dir' + # root_dir = os.path.dirname(os.path.abspath('.')) + # logging.debug('the current root_dir is %s' % root_dir) + project_dir = os.path.abspath('.') + # logging.debug('the current project_dir is %s' % project_dir) + # src_dir = os.path.join(project_dir, 'src') + # logging.debug('the current src_dir is %s' % src_dir) + out_dir = os.path.join(project_dir, 'out') + # logging.debug('the current out_dir is %s' % out_dir) + output_dir = os.path.join(out_dir, output_dir_name) + if not os.path.exists(output_dir): + os.makedirs(output_dir) + # logging.debug('the current output_dir is %s' % output_dir) + return output_dir + + +def mk_children_dir(output_dir_name, sub_dir_name): + 'the initialize children dir' + if not os.path.exists(output_dir_name): + os.makedirs(output_dir_name) + children_dir = os.path.join(output_dir_name, sub_dir_name) + if not os.path.exists(children_dir): + os.makedirs(children_dir) + logging.debug('the current children_dir is %s' % children_dir) + return children_dir diff --git a/src/http/__init__.py b/src/http/__init__.py new file mode 100644 index 0000000..380474e --- /dev/null +++ b/src/http/__init__.py @@ -0,0 +1 @@ +# -*- coding:utf-8 -*- diff --git a/template/__init__.py b/template/__init__.py new file mode 100644 index 0000000..380474e --- /dev/null +++ b/template/__init__.py @@ -0,0 +1 @@ +# -*- coding:utf-8 -*- diff --git a/test/dir/__init__.py b/test/dir/__init__.py new file mode 100644 index 0000000..380474e --- /dev/null +++ b/test/dir/__init__.py @@ -0,0 +1 @@ +# -*- coding:utf-8 -*- diff --git a/test/dir/test_common_dir.py b/test/dir/test_common_dir.py new file mode 100644 index 0000000..90d64d8 --- /dev/null +++ b/test/dir/test_common_dir.py @@ -0,0 +1,48 @@ +# -*- coding:utf-8 -*- + +import unittest + +from dir.common_dir import generate_complex_file_name, generate_file_name, mk_children_dir, mk_output_dir + + +class Test_Common_Dir(unittest.TestCase): + ''' the test demo ''' + @classmethod + def setUpClass(cls): + print("...the set up...") + + def setUp(self): + return super(Test_Common_Dir, self).setUp() + + def test_generate_complex_file_name(self): + dir_name = 'https' + file_name = 'test_name' + output = generate_complex_file_name(dir_name, file_name) + print("\nthe test generate_complex_file_name(%s) is succeed." % output) + + def test_generate_file_name(self): + dir_name = 'https' + file_name = 'test_name' + output = generate_file_name(dir_name, file_name) + print("\nthe test test_generate_file_name(%s) is succeed." % output) + + def test_mk_output_dir(self): + dir_name = 'https' + output = mk_output_dir(dir_name) + print("\nthe test mk_output_dir(%s) is succeed." % output) + + def test_mk_children_dir(self): + sub_name = 'children' + output = mk_children_dir('out/http', sub_dir_name=sub_name) + print("\nthe test mk_children_dir(%s) is succeed." % output) + + def tearDown(self): + return super(Test_Common_Dir, self).tearDown() + + @classmethod + def tearDownClass(cls): + print("...the tear down...") + + +if __name__ == '__main__': + unittest.main() From 4dae5af07ecae96352be79d35beef24637187409 Mon Sep 17 00:00:00 2001 From: zhenwei-li Date: Fri, 27 Nov 2020 16:54:55 +0800 Subject: [PATCH 11/16] =?UTF-8?q?=E7=BD=91=E7=BB=9C=E8=AF=B7=E6=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/http/https.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/http/https.py diff --git a/src/http/https.py b/src/http/https.py new file mode 100644 index 0000000..af68c4a --- /dev/null +++ b/src/http/https.py @@ -0,0 +1,31 @@ +# coding:utf-8 + +import urllib2 +import logging +from conf.common_conf import logging_conf + + +class Request(object): + 'the request class' + + def __init__(self): + super(Request, self).__init__() + + def requests(self, req_url): + 'the request address' + logging.info('this request url is %s' % req_url) + response = urllib2.urlopen(req_url) + headers = response.headers + if any(headers): + logging.debug('this request headers is %s' % str(headers.dict)) + + response_to_string = str(response.read()) + logging.debug('this is response is %s' % response_to_string) + return response + + +if __name__ == "__main__": + logging_conf() + request = Request() + url = 'https://www.zhihu.com/hot' + response = request.requests(url) From 35a8e7703f0973c9e4d98bbd6d64b26d258e2210 Mon Sep 17 00:00:00 2001 From: zhenwei-li Date: Fri, 4 Dec 2020 11:00:19 +0800 Subject: [PATCH 12/16] the README upgrade --- README.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/README.md b/README.md index c3b42d4..8b46674 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ Python DeMo - [1.2 venv3](#12-venv3) - [1.2.1 venv3 for mac](#121-venv3-for-mac) - [1.2.2 venv3 for windows](#122-venv3-for-windows) +- [二. 多模块配置](#二-多模块配置) ## 一. 构建`venv`环境 @@ -48,3 +49,22 @@ python3 -m virtualenv -p C:\Python\Python38\python3.exe venv python3 -m virtualenv -p C:\Python\Python38\python3.exe venv > venv.log ``` + +## 二. 多模块配置 + +具体步骤: + +1. 在`venv2`和`venv` 下新建一个`python.pth`文件,具体目录为`venv2/lib/python2.x/site-packages/python.pth`和`venv/lib/python3.x/site-packages/python.pth`; +2. 在上述`python.pth`文件中写入多模块的`绝对路径`(自己设备上实际目录); + +```python +# venv2 环境 +# /Users/.../Python-DeMo/venv2/lib/python2.x/site-packages/python.pth +# +# venv 环境 +# /Users/.../Python-DeMo/venv/lib/python3.x/site-packages/python.pth + +/Users/.../Python-DeMo/src +/Users/.../Python-DeMo/test +/Users/.../Python-DeMo/mock +``` From 6039c050651c45c6d88c7fce023fad97184cd6f5 Mon Sep 17 00:00:00 2001 From: zhenwei-li Date: Fri, 4 Dec 2020 11:27:31 +0800 Subject: [PATCH 13/16] to add .editorconfig --- .editorconfig | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..3af2b9d --- /dev/null +++ b/.editorconfig @@ -0,0 +1,18 @@ +# Configuration file for EditorConfig +# More information is available under http://EditorConfig.org + +# Ignore any other files further up in the file system +root = true + +# Configuration for all files +[*] +# Enforce Unix style line endings (\n only) +end_of_line = lf +# Always end files with a blank line +insert_final_newline = true +# Force space characters for indentation +indent_style = space +# Always indent by 4 characters +indent_size = 4 +# Remove whitespace characters at the end of line +trim_trailing_whitespace = true From 42cf19290547be67831b05cb6aa482b687d8cc32 Mon Sep 17 00:00:00 2001 From: zhenwei-li Date: Mon, 7 Dec 2020 17:04:15 +0800 Subject: [PATCH 14/16] the http test case --- src/dir/common_dir.py | 6 ++-- src/http/https.py | 39 ++++++++++++++------- test/dir/test_common_dir.py | 7 +++- test/http/__init__.py | 1 + test/http/test_https.py | 67 +++++++++++++++++++++++++++++++++++++ 5 files changed, 104 insertions(+), 16 deletions(-) create mode 100644 test/http/__init__.py create mode 100644 test/http/test_https.py diff --git a/src/dir/common_dir.py b/src/dir/common_dir.py index cd45352..e6a79b9 100644 --- a/src/dir/common_dir.py +++ b/src/dir/common_dir.py @@ -1,5 +1,7 @@ +# -*- coding:utf-8 -*- + import os -import logging +# import logging import time @@ -40,5 +42,5 @@ def mk_children_dir(output_dir_name, sub_dir_name): children_dir = os.path.join(output_dir_name, sub_dir_name) if not os.path.exists(children_dir): os.makedirs(children_dir) - logging.debug('the current children_dir is %s' % children_dir) + # logging.debug('the current children_dir is %s' % children_dir) return children_dir diff --git a/src/http/https.py b/src/http/https.py index af68c4a..6f162ac 100644 --- a/src/http/https.py +++ b/src/http/https.py @@ -1,31 +1,44 @@ -# coding:utf-8 +# -*- coding:utf-8 -*- +from conf.common_conf import logging_conf import urllib2 import logging -from conf.common_conf import logging_conf class Request(object): 'the request class' - def __init__(self): + _url = None # the request url address + + # def __init__(self): + # super(Request, self).__init__() + # logging_conf() + + def __init__(self, *url): super(Request, self).__init__() + self._url = url + logging_conf() - def requests(self, req_url): + def requests(self, *req_url): 'the request address' + if len(req_url) == 0 or req_url is None: + req_url = self._url + if len(req_url) == 0: + return logging.info('this request url is %s' % req_url) - response = urllib2.urlopen(req_url) + response = urllib2.urlopen(req_url[0]) headers = response.headers if any(headers): logging.debug('this request headers is %s' % str(headers.dict)) - response_to_string = str(response.read()) - logging.debug('this is response is %s' % response_to_string) + # response_to_string = str(response.read()) + # logging.debug('this is response is %s' % response_to_string) return response - -if __name__ == "__main__": - logging_conf() - request = Request() - url = 'https://www.zhihu.com/hot' - response = request.requests(url) + def getUrl(self): + 'the get url' + if not len(self._url) == 0: + logging.info('the current url is %s' % self._url) + else: + logging.info('the current url is empty') + return self._url diff --git a/test/dir/test_common_dir.py b/test/dir/test_common_dir.py index 90d64d8..607d80b 100644 --- a/test/dir/test_common_dir.py +++ b/test/dir/test_common_dir.py @@ -6,7 +6,7 @@ class Test_Common_Dir(unittest.TestCase): - ''' the test demo ''' + ''' the test common dir ''' @classmethod def setUpClass(cls): print("...the set up...") @@ -19,22 +19,27 @@ def test_generate_complex_file_name(self): file_name = 'test_name' output = generate_complex_file_name(dir_name, file_name) print("\nthe test generate_complex_file_name(%s) is succeed." % output) + self.assertIsNotNone(output, + 'test_generate_complex_file_name is error.') def test_generate_file_name(self): dir_name = 'https' file_name = 'test_name' output = generate_file_name(dir_name, file_name) print("\nthe test test_generate_file_name(%s) is succeed." % output) + self.assertIsNotNone(output, 'test_generate_file_name is error.') def test_mk_output_dir(self): dir_name = 'https' output = mk_output_dir(dir_name) print("\nthe test mk_output_dir(%s) is succeed." % output) + self.assertIsNotNone(output, 'test_mk_output_dir is error.') def test_mk_children_dir(self): sub_name = 'children' output = mk_children_dir('out/http', sub_dir_name=sub_name) print("\nthe test mk_children_dir(%s) is succeed." % output) + self.assertIsNotNone(output, 'test_mk_children_dir is error.') def tearDown(self): return super(Test_Common_Dir, self).tearDown() diff --git a/test/http/__init__.py b/test/http/__init__.py new file mode 100644 index 0000000..380474e --- /dev/null +++ b/test/http/__init__.py @@ -0,0 +1 @@ +# -*- coding:utf-8 -*- diff --git a/test/http/test_https.py b/test/http/test_https.py new file mode 100644 index 0000000..a7e86df --- /dev/null +++ b/test/http/test_https.py @@ -0,0 +1,67 @@ +# -*- coding:utf-8 -*- + +import unittest +from http.https import Request + + +def test_two(): + # the origin request object, then test case two + # _request = Request(url) + # _request.requests() + pass + + +class Test_Https(unittest.TestCase): + ''' the test https ''' + @classmethod + def setUpClass(cls): + print("...the set up...") + print + + def setUp(self): + return super(Test_Https, self).setUp() + + def test_requests_one(self): + 'the test requests one' + # url = 'http://www.xuexi.la/sudu/523441.html' + _request = Request() + self.assertIsNotNone(_request, 'test_requests_one is error.') + self.assertIsNone(_request.requests()) + + def test_requests_two(self): + 'the test requests two' + url = 'http://www.xuexi.la/sudu/523441.html' + _request = Request(url) + self.assertIsNotNone(_request, 'test_requests_two is error') + response = _request.requests() + self.assertIsNotNone(response, 'test_requests_two is error.') + + def test_requests_three(self): + 'the test requests three' + url = 'http://www.xuexi.la/sudu/523441.html' + _request = Request() + self.assertIsNotNone(_request, 'test_requests_three is error') + response = _request.requests(url) + self.assertIsNotNone(_request.getUrl(), + 'test_requests_three is error.') + self.assertIsNotNone(response, 'test_requests_three is error.') + + def test_getUrl(self): + 'the test get url' + url = 'http://www.xuexi.la/sudu/523441.html' + _request = Request(url) + self.assertIsNotNone(_request.getUrl(), 'test_getUrl is error.') + _request = Request() + self.assertTupleEqual(_request.getUrl(), (), 'test_getUrl is error.') + + def tearDown(self): + return super(Test_Https, self).tearDown() + + @classmethod + def tearDownClass(cls): + print + print("...the tear down...") + + +if __name__ == '__main__': + unittest.main() From 4717d8fd082ec0ebd57717aed150c19989630d1e Mon Sep 17 00:00:00 2001 From: zhenwei-li Date: Mon, 7 Dec 2020 18:16:59 +0800 Subject: [PATCH 15/16] the common conf test case --- src/conf/common_conf.py | 15 ++++++-- src/http/https.py | 6 ++- .../{template_test.py => test_template.py} | 0 test/conf/__init__.py | 1 + test/conf/test_common_conf.py | 37 +++++++++++++++++++ 5 files changed, 54 insertions(+), 5 deletions(-) rename template/{template_test.py => test_template.py} (100%) create mode 100644 test/conf/__init__.py create mode 100644 test/conf/test_common_conf.py diff --git a/src/conf/common_conf.py b/src/conf/common_conf.py index 95fd302..53afa70 100644 --- a/src/conf/common_conf.py +++ b/src/conf/common_conf.py @@ -4,9 +4,18 @@ from dir.common_dir import generate_complex_file_name -def logging_conf(): - 'the logging conf info' - file_name = generate_complex_file_name('http', 'http') +def logging_conf(kwargs): + ''' + the logging conf info: + logging_conf(**kwargs={output_dir_name=\' \', file_name=\' \'}) + ''' + if kwargs.get('output_dir_name') is None or len( + kwargs.get('output_dir_name')) == 0: + raise KeyError('the current kwargs[output_dir_name] is empty.') + if kwargs.get('file_name') is None or len(kwargs.get('file_name')) == 0: + raise KeyError('the current kwargs[file_name] is empty.') + file_name = generate_complex_file_name(kwargs['output_dir_name'], + kwargs['file_name']) logging.basicConfig( filename=file_name, filemode='a', diff --git a/src/http/https.py b/src/http/https.py index 6f162ac..d54ee07 100644 --- a/src/http/https.py +++ b/src/http/https.py @@ -12,12 +12,14 @@ class Request(object): # def __init__(self): # super(Request, self).__init__() - # logging_conf() + # kwargs = {'output_dir_name': 'request', 'file_name': 'request'} + # logging_conf(kwargs) def __init__(self, *url): super(Request, self).__init__() self._url = url - logging_conf() + kwargs = {'output_dir_name': 'request', 'file_name': 'request'} + logging_conf(kwargs) def requests(self, *req_url): 'the request address' diff --git a/template/template_test.py b/template/test_template.py similarity index 100% rename from template/template_test.py rename to template/test_template.py diff --git a/test/conf/__init__.py b/test/conf/__init__.py new file mode 100644 index 0000000..380474e --- /dev/null +++ b/test/conf/__init__.py @@ -0,0 +1 @@ +# -*- coding:utf-8 -*- diff --git a/test/conf/test_common_conf.py b/test/conf/test_common_conf.py new file mode 100644 index 0000000..5a91a95 --- /dev/null +++ b/test/conf/test_common_conf.py @@ -0,0 +1,37 @@ +# -*- coding:utf-8 -*- + +import unittest +from conf.common_conf import logging_conf + + +class Test_Common_Conf(unittest.TestCase): + ''' the test common conf ''' + @classmethod + def setUpClass(cls): + print("...the set up...") + print + + def setUp(self): + return super(Test_Common_Conf, self).setUp() + + def test_logging_conf(self): + 'the test logging conf' + # kwargs = {'output_dir_name': ' ', 'file_name': ' '} + # kwargs = {'output_dir_name': 'request', 'file_name': ' '} + # kwargs = {'output_dir_name': ' ', 'file_name': 'request'} + kwargs = {'output_dir_name': 'request', 'file_name': 'request'} + logging_conf(kwargs) + print "the test test_logging_conf is succeed." + pass + + def tearDown(self): + return super(Test_Common_Conf, self).tearDown() + + @classmethod + def tearDownClass(cls): + print + print("...the tear down...") + + +if __name__ == '__main__': + unittest.main() From 29b9bbaa6e5e9fac0257aff50c78343e496e9f89 Mon Sep 17 00:00:00 2001 From: zhenwei-li Date: Mon, 7 Dec 2020 18:31:35 +0800 Subject: [PATCH 16/16] =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=B7=A5=E7=A8=8B?= =?UTF-8?q?=E7=9B=AE=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + {src/conf => case/argparse}/__init__.py | 0 {src/dir => case/class}/__init__.py | 0 {src/http => case/file}/__init__.py | 0 {test/conf => case/function}/__init__.py | 0 {test/dir => case/logging}/__init__.py | 0 .../standard_library}/__init__.py | 0 src/com/__init__.py | 1 + src/com/dvsnier/__init__.py | 1 + src/com/dvsnier/conf/__init__.py | 1 + src/{ => com/dvsnier}/conf/common_conf.py | 2 +- src/com/dvsnier/dir/__init__.py | 1 + src/{ => com/dvsnier}/dir/common_dir.py | 0 src/com/dvsnier/http/__init__.py | 1 + src/{ => com/dvsnier}/http/https.py | 2 +- src/demo/__init__.py | 1 + src/demo/http_case.py | 20 +++++++++++++++++++ test/com/__init__.py | 1 + test/com/dvsnier/__init__.py | 1 + test/com/dvsnier/conf/__init__.py | 1 + .../dvsnier}/conf/test_common_conf.py | 2 +- test/com/dvsnier/dir/__init__.py | 1 + test/{ => com/dvsnier}/dir/test_common_dir.py | 2 +- test/com/dvsnier/http/__init__.py | 1 + test/{ => com/dvsnier}/http/test_https.py | 2 +- 25 files changed, 37 insertions(+), 5 deletions(-) rename {src/conf => case/argparse}/__init__.py (100%) rename {src/dir => case/class}/__init__.py (100%) rename {src/http => case/file}/__init__.py (100%) rename {test/conf => case/function}/__init__.py (100%) rename {test/dir => case/logging}/__init__.py (100%) rename {test/http => case/standard_library}/__init__.py (100%) create mode 100644 src/com/__init__.py create mode 100644 src/com/dvsnier/__init__.py create mode 100644 src/com/dvsnier/conf/__init__.py rename src/{ => com/dvsnier}/conf/common_conf.py (93%) create mode 100644 src/com/dvsnier/dir/__init__.py rename src/{ => com/dvsnier}/dir/common_dir.py (100%) create mode 100644 src/com/dvsnier/http/__init__.py rename src/{ => com/dvsnier}/http/https.py (96%) create mode 100644 src/demo/__init__.py create mode 100644 src/demo/http_case.py create mode 100644 test/com/__init__.py create mode 100644 test/com/dvsnier/__init__.py create mode 100644 test/com/dvsnier/conf/__init__.py rename test/{ => com/dvsnier}/conf/test_common_conf.py (94%) create mode 100644 test/com/dvsnier/dir/__init__.py rename test/{ => com/dvsnier}/dir/test_common_dir.py (93%) create mode 100644 test/com/dvsnier/http/__init__.py rename test/{ => com/dvsnier}/http/test_https.py (97%) diff --git a/README.md b/README.md index 8b46674..a90f8f8 100644 --- a/README.md +++ b/README.md @@ -67,4 +67,5 @@ python3 -m virtualenv -p C:\Python\Python38\python3.exe venv > venv.log /Users/.../Python-DeMo/src /Users/.../Python-DeMo/test /Users/.../Python-DeMo/mock +/Users/.../Python-DeMo/case ``` diff --git a/src/conf/__init__.py b/case/argparse/__init__.py similarity index 100% rename from src/conf/__init__.py rename to case/argparse/__init__.py diff --git a/src/dir/__init__.py b/case/class/__init__.py similarity index 100% rename from src/dir/__init__.py rename to case/class/__init__.py diff --git a/src/http/__init__.py b/case/file/__init__.py similarity index 100% rename from src/http/__init__.py rename to case/file/__init__.py diff --git a/test/conf/__init__.py b/case/function/__init__.py similarity index 100% rename from test/conf/__init__.py rename to case/function/__init__.py diff --git a/test/dir/__init__.py b/case/logging/__init__.py similarity index 100% rename from test/dir/__init__.py rename to case/logging/__init__.py diff --git a/test/http/__init__.py b/case/standard_library/__init__.py similarity index 100% rename from test/http/__init__.py rename to case/standard_library/__init__.py diff --git a/src/com/__init__.py b/src/com/__init__.py new file mode 100644 index 0000000..380474e --- /dev/null +++ b/src/com/__init__.py @@ -0,0 +1 @@ +# -*- coding:utf-8 -*- diff --git a/src/com/dvsnier/__init__.py b/src/com/dvsnier/__init__.py new file mode 100644 index 0000000..380474e --- /dev/null +++ b/src/com/dvsnier/__init__.py @@ -0,0 +1 @@ +# -*- coding:utf-8 -*- diff --git a/src/com/dvsnier/conf/__init__.py b/src/com/dvsnier/conf/__init__.py new file mode 100644 index 0000000..380474e --- /dev/null +++ b/src/com/dvsnier/conf/__init__.py @@ -0,0 +1 @@ +# -*- coding:utf-8 -*- diff --git a/src/conf/common_conf.py b/src/com/dvsnier/conf/common_conf.py similarity index 93% rename from src/conf/common_conf.py rename to src/com/dvsnier/conf/common_conf.py index 53afa70..34801c8 100644 --- a/src/conf/common_conf.py +++ b/src/com/dvsnier/conf/common_conf.py @@ -1,7 +1,7 @@ # -*- coding:utf-8 -*- import logging -from dir.common_dir import generate_complex_file_name +from com.dvsnier.dir.common_dir import generate_complex_file_name def logging_conf(kwargs): diff --git a/src/com/dvsnier/dir/__init__.py b/src/com/dvsnier/dir/__init__.py new file mode 100644 index 0000000..380474e --- /dev/null +++ b/src/com/dvsnier/dir/__init__.py @@ -0,0 +1 @@ +# -*- coding:utf-8 -*- diff --git a/src/dir/common_dir.py b/src/com/dvsnier/dir/common_dir.py similarity index 100% rename from src/dir/common_dir.py rename to src/com/dvsnier/dir/common_dir.py diff --git a/src/com/dvsnier/http/__init__.py b/src/com/dvsnier/http/__init__.py new file mode 100644 index 0000000..380474e --- /dev/null +++ b/src/com/dvsnier/http/__init__.py @@ -0,0 +1 @@ +# -*- coding:utf-8 -*- diff --git a/src/http/https.py b/src/com/dvsnier/http/https.py similarity index 96% rename from src/http/https.py rename to src/com/dvsnier/http/https.py index d54ee07..8c52dd0 100644 --- a/src/http/https.py +++ b/src/com/dvsnier/http/https.py @@ -1,6 +1,6 @@ # -*- coding:utf-8 -*- -from conf.common_conf import logging_conf +from com.dvsnier.conf.common_conf import logging_conf import urllib2 import logging diff --git a/src/demo/__init__.py b/src/demo/__init__.py new file mode 100644 index 0000000..380474e --- /dev/null +++ b/src/demo/__init__.py @@ -0,0 +1 @@ +# -*- coding:utf-8 -*- diff --git a/src/demo/http_case.py b/src/demo/http_case.py new file mode 100644 index 0000000..775ebd6 --- /dev/null +++ b/src/demo/http_case.py @@ -0,0 +1,20 @@ +# -*- coding:utf-8 -*- + +from com.dvsnier.http.https import Request +from com.dvsnier.dir.common_dir import generate_complex_file_name + +_request = None + + +def run(url): + return _request.requests(url) + + +if __name__ == "__main__": + _request = Request() + url = 'http://www.xuexi.la/sudu/523441.html' + # url = 'https://www.thepaper.cn/newsDetail_forward_9864719' + response = run(url) + response_file = generate_complex_file_name('request', 'response') + with open(response_file, 'w+') as f: + f.write(str(response.read())) diff --git a/test/com/__init__.py b/test/com/__init__.py new file mode 100644 index 0000000..380474e --- /dev/null +++ b/test/com/__init__.py @@ -0,0 +1 @@ +# -*- coding:utf-8 -*- diff --git a/test/com/dvsnier/__init__.py b/test/com/dvsnier/__init__.py new file mode 100644 index 0000000..380474e --- /dev/null +++ b/test/com/dvsnier/__init__.py @@ -0,0 +1 @@ +# -*- coding:utf-8 -*- diff --git a/test/com/dvsnier/conf/__init__.py b/test/com/dvsnier/conf/__init__.py new file mode 100644 index 0000000..380474e --- /dev/null +++ b/test/com/dvsnier/conf/__init__.py @@ -0,0 +1 @@ +# -*- coding:utf-8 -*- diff --git a/test/conf/test_common_conf.py b/test/com/dvsnier/conf/test_common_conf.py similarity index 94% rename from test/conf/test_common_conf.py rename to test/com/dvsnier/conf/test_common_conf.py index 5a91a95..2080409 100644 --- a/test/conf/test_common_conf.py +++ b/test/com/dvsnier/conf/test_common_conf.py @@ -1,7 +1,7 @@ # -*- coding:utf-8 -*- import unittest -from conf.common_conf import logging_conf +from com.dvsnier.conf.common_conf import logging_conf class Test_Common_Conf(unittest.TestCase): diff --git a/test/com/dvsnier/dir/__init__.py b/test/com/dvsnier/dir/__init__.py new file mode 100644 index 0000000..380474e --- /dev/null +++ b/test/com/dvsnier/dir/__init__.py @@ -0,0 +1 @@ +# -*- coding:utf-8 -*- diff --git a/test/dir/test_common_dir.py b/test/com/dvsnier/dir/test_common_dir.py similarity index 93% rename from test/dir/test_common_dir.py rename to test/com/dvsnier/dir/test_common_dir.py index 607d80b..6434972 100644 --- a/test/dir/test_common_dir.py +++ b/test/com/dvsnier/dir/test_common_dir.py @@ -2,7 +2,7 @@ import unittest -from dir.common_dir import generate_complex_file_name, generate_file_name, mk_children_dir, mk_output_dir +from com.dvsnier.dir.common_dir import generate_complex_file_name, generate_file_name, mk_children_dir, mk_output_dir class Test_Common_Dir(unittest.TestCase): diff --git a/test/com/dvsnier/http/__init__.py b/test/com/dvsnier/http/__init__.py new file mode 100644 index 0000000..380474e --- /dev/null +++ b/test/com/dvsnier/http/__init__.py @@ -0,0 +1 @@ +# -*- coding:utf-8 -*- diff --git a/test/http/test_https.py b/test/com/dvsnier/http/test_https.py similarity index 97% rename from test/http/test_https.py rename to test/com/dvsnier/http/test_https.py index a7e86df..69b230e 100644 --- a/test/http/test_https.py +++ b/test/com/dvsnier/http/test_https.py @@ -1,7 +1,7 @@ # -*- coding:utf-8 -*- import unittest -from http.https import Request +from com.dvsnier.http.https import Request def test_two():