This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import unittest | |
def sum(x, y): | |
return x + y | |
class Hoge(unittest.TestCase): | |
def test_sum(self): | |
# テストパタンをlistで用意する |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import unittest | |
# テストしたい関数のあるモジュールをimport | |
import hoge | |
# クラス名はなんでも良いが、unittest.TestCaseの継承は必須 | |
class Hoge(unittest.TestCase): | |
# unittestでは関数名がtest〜で始まる関数をテストコードとして扱う。 | |
# test〜としておかないとテストが実行されないので注意。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import datetime | |
TRIAL_NUM = 1000000 | |
from_ts = datetime.datetime.fromtimestamp | |
def main(): | |
# unixtimeからdatetime作成する処理を100万回 | |
start = time.time() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import argparse | |
def init(): | |
print('initが実行されたよー') | |
def pull(): | |
print('pullが実行されたよー') | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import argparse | |
class Sample(): | |
def __init__(self): | |
self.__num = 0 | |
def add(self, x): | |
self.__num += x |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import unittest | |
# 標準出力をみるためのモジュール達 | |
import sys | |
from io import StringIO | |
from contextlib import redirect_stdout | |
# テスト対象 | |
import sample |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 設定したいデフォルト値 | |
default_configs = {'section1': {'hoge': '0000', | |
'fuga': 9999}, | |
'section2': {'hoge': 'hoge_value'}} | |
# configparserのインスタンスを生成 | |
config = configparser.ConfigParser() | |
# デフォルト値を設定する(コンフィグファイルを読み込む前に設定しないと逆にデフォルト値で上書きされるので注意) | |
config.read_dict(default_configs) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import configparser | |
def main(): | |
# configparserのインスタンスを生成 | |
config = configparser.ConfigParser() | |
# コンフィグファイルを読み込み | |
config.read('./sample.conf') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# でコメント行を表す。 | |
; もコメント行を表す。 | |
### 基本的な書き方 ### | |
# []でセクション、<項目名=値>の形式で各項目を表す。値は全て文字列として扱われる。 | |
[SECTION1] | |
HOGE=0123 | |
# 同じ項目名が複数存在するとエラーになる。 | |
# 大文字・小文字の区別はされないので以下のような値もエラーになるので注意。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
#include <strstream> | |
#include <boost/property_tree/ptree.hpp> | |
#include <boost/property_tree/ini_parser.hpp> | |
namespace pt = boost::property_tree; | |
int main(const int ac, const char* const * const av) | |
{ |