add repr to cmd.chcp

This commit is contained in:
Prodesire 2017-12-22 19:05:11 +08:00
parent 0b0a0ba2f7
commit 22703bbebf
2 changed files with 6 additions and 1 deletions

View File

@ -73,6 +73,7 @@ if WINDOWS:
"""
def __init__(self, code):
self.origin_code = windll.kernel32.GetConsoleOutputCP()
self.code = code
windll.kernel32.SetConsoleOutputCP(code)
def __enter__(self):
@ -80,3 +81,6 @@ if WINDOWS:
def __exit__(self, exc_type, exc_val, exc_tb):
windll.kernel32.SetConsoleOutputCP(self.origin_code)
def __repr__(self):
return '<active code page number: {}>'.format(self.code)

View File

@ -37,7 +37,8 @@ def test_chcp():
assert windll.kernel32.GetConsoleOutputCP() == origin_code
try:
chcp(437)
cp = chcp(437)
assert windll.kernel32.GetConsoleOutputCP() == 437
assert str(cp) == '<active code page number: 437>'
finally:
windll.kernel32.SetConsoleOutputCP(origin_code)