Created
May 1, 2018 08:05
-
-
Save pypeach/75d583be0bd7a7838d9537eab75d04a1 to your computer and use it in GitHub Desktop.
CSV書き込みテスト
This file contains 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
# coding:utf-8 | |
import unittest | |
from app.write_csv_file import WriteCsvFile | |
from sql import emp | |
from test.unit_test_base import UnitTestBase | |
""" | |
CSVファイル書き込みを行うサンプルアプリケーションのテストです | |
""" | |
__author__ = "t.ebinuma" | |
__version__ = "1.0" | |
__date__ = "29 April 2018" | |
class WriteCsvFileTest(UnitTestBase): | |
def test_write_csv_file_001(self): | |
""" | |
ファイルの書き込み結果を検証するテストケースです | |
""" | |
# アプリケーションを初期化する | |
app_class = WriteCsvFile() | |
# テーブルをクリアする | |
self.cleanup_table("emp") | |
# テーブルに初期データを登録する | |
self.run_sql("emp_001") | |
# テーブル登録結果を検証する | |
self.assertEqual(len(emp.select([])), 4) | |
# テーブルを読み込みCSVファイルを作成する | |
app_class.write_csv_file() | |
# ファイルが存在することをチェックする | |
self.assert_file_exists(app_class.csv_file) | |
# 0バイトファイルでないことをチェックする | |
self.assert_file_not_empty(app_class.csv_file) | |
# ファイルパスを作成する | |
expected_file_path = self.get_data_file_path('write_file_001.csv') | |
# 出力したファイルと想定ファイルの内容が同じであることをチェックする | |
self.assert_file_equals(app_class.csv_file, expected_file_path) | |
def test_write_csv_file_002(self): | |
""" | |
ファイルの書き込み結果を検証するテストケースです | |
出力ファイルと想定ファイルで一部データが異なる | |
""" | |
# アプリケーションを初期化する | |
app_class = WriteCsvFile() | |
# テーブルをクリアする | |
self.cleanup_table("emp") | |
# テーブルに初期データを登録する | |
self.run_sql("emp_001") | |
# テーブル登録結果を検証する | |
self.assertEqual(len(emp.select([])), 4) | |
# テーブルを読み込みCSVファイルを作成する | |
app_class.write_csv_file() | |
# ファイルが存在することをチェックする | |
self.assert_file_exists(app_class.csv_file) | |
# 0バイトファイルでないことをチェックする | |
self.assert_file_not_empty(app_class.csv_file) | |
# ファイルパスを作成する | |
expected_file_path = self.get_data_file_path('write_file_002.csv') | |
# 2ファイルの内容が同じであることをチェックする | |
self.assert_file_not_equals(app_class.csv_file, expected_file_path) | |
def test_write_csv_file_003(self): | |
""" | |
0件ファイルを出力するテストケースです | |
""" | |
# アプリケーションを初期化する | |
app_class = WriteCsvFile() | |
# テーブルに初期データを登録する | |
self.cleanup_table("emp") | |
# テーブル登録結果を検証する | |
self.assertEqual(len(emp.select([])), 0) | |
# テーブルを読み込みCSVファイルを作成する | |
app_class.write_csv_file() | |
# ファイルが存在することをチェックする | |
self.assert_file_exists(app_class.csv_file) | |
# 0バイトファイルであることをチェックする | |
self.assert_file_empty(app_class.csv_file) | |
if __name__ == '__main__': | |
unittest.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment