-
Notifications
You must be signed in to change notification settings - Fork 1
/
config_python.py
72 lines (55 loc) · 1.79 KB
/
config_python.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
username = "AtCoderのユーザ名を入れる"
password = "AtCoderのパスワードを入れる"
# 保存したいファイルのルートディレクトリ
root_dir = "~/"
# 保存したい問題, 保存先ディレクトリ, 保存ファイル名
target = [['_a', root_dir + "a/", "sample_inputs.py"],
['_b', root_dir + "b/", "sample_inputs.py"],
['_c', root_dir + "c/", "sample_inputs.py"],
['_d', root_dir + "d/", "sample_inputs.py"],
['_e', root_dir + "e/", "sample_inputs.py"]]
# 出力フォーマットを指定
## ファイル最初に書く宣言等
initial = '''#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from main import main
import unittest
import sys
import io
class TestCases(unittest.TestCase):
'''
sample_format = '''
def test_{sample_number}(self):
stub_stdin(self, \'\'\'{input}
\'\'\')
stub_stdouts(self)
main()
self.assertEqual(sys.stdout.getvalue(), \"{output}\\n\")
'''
## ファイル終わりに書く宣言等
last = """
class StringIO(io.StringIO):
def __init__(self, value=''):
value = value.encode('utf8', 'backslashreplace').decode('utf8')
io.StringIO.__init__(self, value)
def write(self, msg):
io.StringIO.write(self, msg.encode(
'utf8', 'backslashreplace').decode('utf8'))
def stub_stdin(testcase_inst, inputs):
stdin = sys.stdin
def cleanup():
sys.stdin = stdin
testcase_inst.addCleanup(cleanup)
sys.stdin = StringIO(inputs)
def stub_stdouts(testcase_inst):
stderr = sys.stderr
stdout = sys.stdout
def cleanup():
sys.stderr = stderr
sys.stdout = stdout
testcase_inst.addCleanup(cleanup)
sys.stderr = StringIO()
sys.stdout = StringIO()
if __name__ == '__main__':
unittest.main()
"""