Skip to content

Commit 7e91872

Browse files
authored
Merge pull request #95 from Alinvor/kernel
[DONE]合并分支
2 parents 00ebff8 + 7e3cdbc commit 7e91872

24 files changed

+820
-49
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ celerybeat-schedule
8383

8484
# Environments
8585
.env
86+
.env/
87+
# dev.env
88+
# test.env
89+
# prep.env
90+
# prod.env
91+
*.env
8692
.venv
8793
env/
8894
venv/

.vscode/launch.json

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,47 @@
11
{
2-
// 使用 IntelliSense 了解相关属性。
2+
// 使用 IntelliSense 了解相关属性。
33
// 悬停以查看现有属性的描述。
44
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
55
"version": "0.2.0",
66
"configurations": [
7+
// {
8+
// "args": [
9+
// "${file}",
10+
// // "1",
11+
// // "-l",
12+
// // "${workspaceFolder}/build/asc.txt",
13+
// // "-h",
14+
// ],
15+
// "console": "integratedTerminal",
16+
// "env": {
17+
// // "PYTEST_ADDOPTS": "--no-cov"
18+
// },
19+
// "module": "pytest",
20+
// "name": "Python: Pytest",
21+
// // "program": "${file}",
22+
// "request": "launch",
23+
// "type": "python",
24+
// },
725
{
8-
"name": "Python: 当前文件",
9-
"type": "python",
10-
"request": "launch",
26+
// "args": [
27+
// "-v",
28+
// "-s",
29+
// // "--disable-pytest-warnings",
30+
// ],
31+
"console": "integratedTerminal",
32+
// "debugOptions": [
33+
// "WaitOnAbnormalExit",
34+
// "WaitOnNormalExit",
35+
// "RedirectOutput"
36+
// ],
37+
"env": {
38+
// "PYTEST_ADDOPTS": "--no-cov"
39+
},
40+
"envFile": "${workspaceFolder}/.env/dev.env",
41+
"name": "Python: The Current File",
1142
"program": "${file}",
12-
"console": "integratedTerminal"
43+
"request": "launch",
44+
"type": "python",
1345
}
1446
]
15-
}
47+
}

.vscode/settings.json

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@
5050
// "python.defaultInterpreterPath": "${workspaceFolder}/venv2/bin/python",
5151
// "python.defaultInterpreterPath": "venv2/bin/python",
5252
// "python.diagnostics.sourceMapsEnabled": true,
53-
"python.envFile": "${workspaceFolder}/.env",
53+
"python.envFile": "${workspaceFolder}/.env/dev.env",
54+
// "python.envFile": "${workspaceFolder}/.env/test.env",
55+
// "python.envFile": "${workspaceFolder}/.env/pred.env",
56+
// "python.envFile": "${workspaceFolder}/.env/prod.env",
5457
// "python.pythonPath": "${workspaceFolder}/venv2/bin/python",
5558
// "python.pythonPath": "venv2/bin/python",
5659
// "python.pythonPath": "venv2\\Scripts\\python.exe",
@@ -83,16 +86,21 @@
8386
// "python.testing.autoTestDiscoverOnSaveEnabled": true,
8487
"python.testing.cwd": "${workspaceFolder}",
8588
"python.testing.nosetestsEnabled": false,
86-
"python.testing.pytestEnabled": false,
87-
"python.testing.unittestEnabled": true,
88-
// https://github.com/microsoft/vscode-python/discussions/15997#discussioncomment-636389
89-
"python.testing.unittestArgs": [
90-
"-v",
89+
"python.testing.pytestEnabled": true,
90+
"python.testing.pytestArgs": [
91+
// "--disable-pytest-warnings",
9192
"-s",
92-
".",
93-
"-p",
94-
"test_*.py"
93+
"-v",
9594
],
95+
"python.testing.unittestEnabled": false,
96+
// https://github.com/microsoft/vscode-python/discussions/15997#discussioncomment-636389
97+
// "python.testing.unittestArgs": [
98+
// "-v",
99+
// "-s",
100+
// ".",
101+
// "-p",
102+
// "test_*.py"
103+
// ],
96104
// "workbench.settings.openDefaultSettings": true,
97105
// "workbench.settings.editor": "ui",
98106
// "workbench.settings.openDefaultKeybindings": true,

case/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# -*- coding:utf-8 -*-

case/abc/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# -*- coding:utf-8 -*-

case/abc/test_abc.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# -*- coding:utf-8 -*-
2+
3+
import abc
4+
import pytest
5+
6+
class Base_ABC():
7+
8+
__metaclass__ = abc.ABCMeta # python 2.x
9+
'''
10+
the ABC class
11+
12+
多态性是指具有不同功能的函数可以使用相同的函数名,这样就可以用一个函数名调用不同内容的函数。
13+
在面向对象方法中一般是这样表述多态性:
14+
15+
向不同的对象发送同一条消息,不同的对象在接收时会产生不同的行为(即方法)也就是说,每个对象可以用自己的方式去响应共同的消息。所谓消息,就是调用函数,不同的行为就是指不同的实现,即执行不同的函数。
16+
'''
17+
def __init__(self):
18+
super(Base_ABC, self).__init__()
19+
20+
@abc.abstractmethod
21+
def onCallback(self):
22+
'the abstract oncallback method'
23+
# raise AttributeError('the subclasses need to be implemented.')
24+
raise NotImplementedError('the subclasses need to be implemented.')
25+
26+
class D(Base_ABC):
27+
28+
def __init__(self):
29+
super(D, self).__init__()
30+
31+
def onCallback(self):
32+
print('class D onCallback method')
33+
pass
34+
35+
36+
class E(Base_ABC):
37+
38+
def __init__(self):
39+
super(E, self).__init__()
40+
41+
def onCallback(self):
42+
print('class E onCallback method')
43+
pass
44+
45+
@pytest.fixture()
46+
def method_abc():
47+
'the method abc'
48+
return Base_ABC()
49+
50+
@pytest.fixture()
51+
def method_d():
52+
'the method d'
53+
return D()
54+
55+
@pytest.fixture()
56+
def method_e():
57+
'the method e'
58+
return E()
59+
60+
def test_needsfiles(tmpdir):
61+
'the test temp files'
62+
print(tmpdir)
63+
64+
def test_inherit(method_abc):
65+
'the test inherit'
66+
# with pytest.raises(Exception) as e:
67+
# pass
68+
try:
69+
method_abc.onCallback()
70+
except TypeError as e:
71+
pass
72+
73+
def test_inherit_with_d(method_d):
74+
'the test inherit with d'
75+
method_d.onCallback()
76+
77+
def test_inherit_with_e(method_e):
78+
'the test inherit with e'
79+
method_e.onCallback()

case/argparse/conftest.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# -*- coding:utf-8 -*-
2+
3+
import logging
4+
import os
5+
import shutil
6+
import tempfile
7+
8+
from com.dvsnier.config.journal.common_config import config
9+
import pytest
10+
11+
kwargs = {'output_dir_name': 'pytest', 'file_name': 'log', 'level': logging.DEBUG}
12+
config(kwargs)
13+
14+
15+
@pytest.fixture(scope="session")
16+
def _temp_dir():
17+
''' _temp_dir '''
18+
temp = tempfile.mkdtemp(prefix='argprase-')
19+
print('\n')
20+
logging.debug('the current temp dir is {}'.format(temp))
21+
yield temp
22+
shutil.rmtree(temp)
23+
24+
25+
@pytest.fixture(scope="session")
26+
def _temp_file():
27+
''' _temp_file '''
28+
fd, temp = tempfile.mkstemp(prefix='argprase-', suffix='.tmp')
29+
# print('\n')
30+
logging.debug('the current temp path is {}'.format(temp))
31+
yield temp
32+
os.remove(temp)

case/argparse/test_argparse.py

Lines changed: 0 additions & 34 deletions
This file was deleted.

case/argparse/test_argparse_0.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# -*- coding:utf-8 -*-
2+
3+
import argparse
4+
5+
6+
def function_argparse():
7+
#
8+
# the command line srcipt:
9+
#
10+
# python test_argparse.py --help
11+
#
12+
parser = argparse.ArgumentParser(description='这是一个基本描述信息。')
13+
14+
# Add optional switches
15+
parser.add_argument('-v', action='store_true', dest='is_verbose', help='produce verbose output')
16+
parser.add_argument('-o',
17+
action='store',
18+
dest='output',
19+
metavar='FILE',
20+
help='direct output to FILE instead of stdout')
21+
parser.add_argument('-C',
22+
action='store',
23+
type=int,
24+
dest='context',
25+
metavar='NUM',
26+
default=0,
27+
help='display NUM lines of added context')
28+
29+
# Allow any number of additional arguments.
30+
parser.add_argument(nargs='*', action='store', dest='inputs', help='input filenames (default is stdin)')
31+
32+
args = parser.parse_args()
33+
print(args.__dict__)
34+
35+
36+
if __name__ == "__main__":
37+
''' the main point '''
38+
function_argparse()

case/argparse/test_argparse_1.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# -*- coding:utf-8 -*-
2+
3+
import argparse
4+
import sys
5+
6+
7+
def function_argparse():
8+
#
9+
# the command line srcipt:
10+
#
11+
# python test_argparse_1.py --help
12+
# python test_argparse_1.py 1
13+
# python test_argparse_1.py 2
14+
# python test_argparse_1.py 12 -l lasc.txt
15+
# python test_argparse_1.py 12 --log asc.txt
16+
#
17+
parser = argparse.ArgumentParser(description='sum the integers at the command line')
18+
# 位置参数
19+
parser.add_argument('integers', metavar='int', nargs='+', type=int, help='an integer to be summed')
20+
# 可选参数
21+
parser.add_argument('-l',
22+
'--log',
23+
default=sys.stdout,
24+
type=argparse.FileType('w'),
25+
help='the file where the sum should be written')
26+
# parser.add_argument("-v", "--verbosity", action="count", default=0, help="increase output verbosity")
27+
# 可选参数,互斥选项
28+
group = parser.add_mutually_exclusive_group()
29+
group.add_argument("-v", "--verbose", action="store_true", help='the verbose info')
30+
group.add_argument("-q", "--quiet", action="store_true", help='the quiet info')
31+
args = parser.parse_args()
32+
33+
# if args.integers:
34+
# args.integers = args.integers**2
35+
if args.log:
36+
args.log.write('%s' % sum(args.integers))
37+
args.log.close()
38+
39+
40+
if __name__ == "__main__":
41+
''' the main point '''
42+
function_argparse()

0 commit comments

Comments
 (0)