Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ celerybeat-schedule

# Environments
.env
.env/
# dev.env
# test.env
# prep.env
# prod.env
*.env
.venv
env/
venv/
Expand Down
44 changes: 38 additions & 6 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,47 @@
{
// 使用 IntelliSense 了解相关属性。
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
// {
// "args": [
// "${file}",
// // "1",
// // "-l",
// // "${workspaceFolder}/build/asc.txt",
// // "-h",
// ],
// "console": "integratedTerminal",
// "env": {
// // "PYTEST_ADDOPTS": "--no-cov"
// },
// "module": "pytest",
// "name": "Python: Pytest",
// // "program": "${file}",
// "request": "launch",
// "type": "python",
// },
{
"name": "Python: 当前文件",
"type": "python",
"request": "launch",
// "args": [
// "-v",
// "-s",
// // "--disable-pytest-warnings",
// ],
"console": "integratedTerminal",
// "debugOptions": [
// "WaitOnAbnormalExit",
// "WaitOnNormalExit",
// "RedirectOutput"
// ],
"env": {
// "PYTEST_ADDOPTS": "--no-cov"
},
"envFile": "${workspaceFolder}/.env/dev.env",
"name": "Python: The Current File",
"program": "${file}",
"console": "integratedTerminal"
"request": "launch",
"type": "python",
}
]
}
}
26 changes: 17 additions & 9 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@
// "python.defaultInterpreterPath": "${workspaceFolder}/venv2/bin/python",
// "python.defaultInterpreterPath": "venv2/bin/python",
// "python.diagnostics.sourceMapsEnabled": true,
"python.envFile": "${workspaceFolder}/.env",
"python.envFile": "${workspaceFolder}/.env/dev.env",
// "python.envFile": "${workspaceFolder}/.env/test.env",
// "python.envFile": "${workspaceFolder}/.env/pred.env",
// "python.envFile": "${workspaceFolder}/.env/prod.env",
// "python.pythonPath": "${workspaceFolder}/venv2/bin/python",
// "python.pythonPath": "venv2/bin/python",
// "python.pythonPath": "venv2\\Scripts\\python.exe",
Expand Down Expand Up @@ -83,16 +86,21 @@
// "python.testing.autoTestDiscoverOnSaveEnabled": true,
"python.testing.cwd": "${workspaceFolder}",
"python.testing.nosetestsEnabled": false,
"python.testing.pytestEnabled": false,
"python.testing.unittestEnabled": true,
// https://github.com/microsoft/vscode-python/discussions/15997#discussioncomment-636389
"python.testing.unittestArgs": [
"-v",
"python.testing.pytestEnabled": true,
"python.testing.pytestArgs": [
// "--disable-pytest-warnings",
"-s",
".",
"-p",
"test_*.py"
"-v",
],
"python.testing.unittestEnabled": false,
// https://github.com/microsoft/vscode-python/discussions/15997#discussioncomment-636389
// "python.testing.unittestArgs": [
// "-v",
// "-s",
// ".",
// "-p",
// "test_*.py"
// ],
// "workbench.settings.openDefaultSettings": true,
// "workbench.settings.editor": "ui",
// "workbench.settings.openDefaultKeybindings": true,
Expand Down
1 change: 1 addition & 0 deletions case/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# -*- coding:utf-8 -*-
1 change: 1 addition & 0 deletions case/abc/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# -*- coding:utf-8 -*-
79 changes: 79 additions & 0 deletions case/abc/test_abc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# -*- coding:utf-8 -*-

import abc
import pytest

class Base_ABC():

__metaclass__ = abc.ABCMeta # python 2.x
'''
the ABC class

多态性是指具有不同功能的函数可以使用相同的函数名,这样就可以用一个函数名调用不同内容的函数。
在面向对象方法中一般是这样表述多态性:

向不同的对象发送同一条消息,不同的对象在接收时会产生不同的行为(即方法)也就是说,每个对象可以用自己的方式去响应共同的消息。所谓消息,就是调用函数,不同的行为就是指不同的实现,即执行不同的函数。
'''
def __init__(self):
super(Base_ABC, self).__init__()

@abc.abstractmethod
def onCallback(self):
'the abstract oncallback method'
# raise AttributeError('the subclasses need to be implemented.')
raise NotImplementedError('the subclasses need to be implemented.')

class D(Base_ABC):

def __init__(self):
super(D, self).__init__()

def onCallback(self):
print('class D onCallback method')
pass


class E(Base_ABC):

def __init__(self):
super(E, self).__init__()

def onCallback(self):
print('class E onCallback method')
pass

@pytest.fixture()
def method_abc():
'the method abc'
return Base_ABC()

@pytest.fixture()
def method_d():
'the method d'
return D()

@pytest.fixture()
def method_e():
'the method e'
return E()

def test_needsfiles(tmpdir):
'the test temp files'
print(tmpdir)

def test_inherit(method_abc):
'the test inherit'
# with pytest.raises(Exception) as e:
# pass
try:
method_abc.onCallback()
except TypeError as e:
pass

def test_inherit_with_d(method_d):
'the test inherit with d'
method_d.onCallback()

def test_inherit_with_e(method_e):
'the test inherit with e'
method_e.onCallback()
32 changes: 32 additions & 0 deletions case/argparse/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# -*- coding:utf-8 -*-

import logging
import os
import shutil
import tempfile

from com.dvsnier.config.journal.common_config import config
import pytest

kwargs = {'output_dir_name': 'pytest', 'file_name': 'log', 'level': logging.DEBUG}
config(kwargs)


@pytest.fixture(scope="session")
def _temp_dir():
''' _temp_dir '''
temp = tempfile.mkdtemp(prefix='argprase-')
print('\n')
logging.debug('the current temp dir is {}'.format(temp))
yield temp
shutil.rmtree(temp)


@pytest.fixture(scope="session")
def _temp_file():
''' _temp_file '''
fd, temp = tempfile.mkstemp(prefix='argprase-', suffix='.tmp')
# print('\n')
logging.debug('the current temp path is {}'.format(temp))
yield temp
os.remove(temp)
34 changes: 0 additions & 34 deletions case/argparse/test_argparse.py

This file was deleted.

38 changes: 38 additions & 0 deletions case/argparse/test_argparse_0.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# -*- coding:utf-8 -*-

import argparse


def function_argparse():
#
# the command line srcipt:
#
# python test_argparse.py --help
#
parser = argparse.ArgumentParser(description='这是一个基本描述信息。')

# Add optional switches
parser.add_argument('-v', action='store_true', dest='is_verbose', help='produce verbose output')
parser.add_argument('-o',
action='store',
dest='output',
metavar='FILE',
help='direct output to FILE instead of stdout')
parser.add_argument('-C',
action='store',
type=int,
dest='context',
metavar='NUM',
default=0,
help='display NUM lines of added context')

# Allow any number of additional arguments.
parser.add_argument(nargs='*', action='store', dest='inputs', help='input filenames (default is stdin)')

args = parser.parse_args()
print(args.__dict__)


if __name__ == "__main__":
''' the main point '''
function_argparse()
42 changes: 42 additions & 0 deletions case/argparse/test_argparse_1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# -*- coding:utf-8 -*-

import argparse
import sys


def function_argparse():
#
# the command line srcipt:
#
# python test_argparse_1.py --help
# python test_argparse_1.py 1
# python test_argparse_1.py 2
# python test_argparse_1.py 12 -l lasc.txt
# python test_argparse_1.py 12 --log asc.txt
#
parser = argparse.ArgumentParser(description='sum the integers at the command line')
# 位置参数
parser.add_argument('integers', metavar='int', nargs='+', type=int, help='an integer to be summed')
# 可选参数
parser.add_argument('-l',
'--log',
default=sys.stdout,
type=argparse.FileType('w'),
help='the file where the sum should be written')
# parser.add_argument("-v", "--verbosity", action="count", default=0, help="increase output verbosity")
# 可选参数,互斥选项
group = parser.add_mutually_exclusive_group()
group.add_argument("-v", "--verbose", action="store_true", help='the verbose info')
group.add_argument("-q", "--quiet", action="store_true", help='the quiet info')
args = parser.parse_args()

# if args.integers:
# args.integers = args.integers**2
if args.log:
args.log.write('%s' % sum(args.integers))
args.log.close()


if __name__ == "__main__":
''' the main point '''
function_argparse()
Loading