pip install pytest pytest-cov pytest-randomly pytest-mock
- pytest-cov: カバレッジ計測プラグイン
- pytest-randomly: 実行順のランダム化
- pytest-mock: mock利用プラグイン
[tool.poetry] | |
name = "poetry-export-issue-2023-05-23" | |
version = "0.1.0" | |
description = "" | |
authors = ["XXX <[email protected]>"] | |
readme = "README.md" | |
packages = [{include = "poetry_export_issue_2023_05_23"}] | |
[tool.poetry.dependencies] | |
python = "^3.10" |
# Pythonで誤って関数に括弧をつけず呼び出した場合にどこまで検知できるか | |
# @shiumachi, 2023/02/22 | |
# Python 3.11.2, mypy 1.0.1 | |
def main(): | |
def func(x: int = 1) -> int: | |
return x | |
# 検知できない例1: 元々callableでも受け付けられる使い方をする場合 | |
print(f"{func=}") |
[flake8] | |
max-line-length = 88 | |
select = C,E,F,W,B,B950 | |
extend-ignore = E203, E501 |
import pathlib | |
import typing | |
import pandas as pd | |
# data definition | |
## valid data | |
df1 = pd.DataFrame( | |
[ | |
{"c1": 100, "c2": "a100"}, |
# phonics | |
ph = {"a": "アッ", "b": "バッ", "c": "カッ", "d": "ダッ", "e": "エ", "f": "フッ", "g": "グッ", "h": "ハッ", "i": "イ", "j": "ジャ", "k": "クッ", "l": "ル", "m": "ム", "n": "ヌ", "o": "オ", "p": "パッ", "q": "カッ", "r": "ル", "s": "ス", "t": "ツ", "u": "ウッ", "v": "ヴッ", "w": "ウッ", "x": "クス", "y": "ヤッ", "z": "ズ"} | |
arr = [] | |
for a,b in ph.items(): | |
arr.append(f'rsub("{a}", "{b}",') | |
result = ''.join(arr) + "{@1}"" + ')' * len(arr) | |
result | |
# upper | |
d = {} |
# -*- coding: utf-8 -*- | |
# Reference: Python Cookbook 2nd Ed. p.188 | |
import random | |
def random_pick(item_list, probabilities): | |
""" return a random item in a list, which has different probability. |
# -*- coding: utf-8 -*- | |
# Reference: Python Cookbook 2 Ed. p.198 | |
def get_sorted_dict_values(d): | |
keys = d.keys() | |
keys.sort() | |
return [d[key] for key in keys] |
import datetime | |
def convert_to_datetime(date_string): | |
""" input: %Y-%m-%d %H:%M:%S,%f | |
example: 2014-01-05 22:20:50,307 | |
return: datetime object | |
""" | |
date_format = "%Y-%m-%d %H:%M:%S,%f" |