mirror of
https://github.com/scito/extract_otp_secret_keys.git
synced 2025-12-13 18:16:37 +01:00
add type hints (Python 3.11)
This commit is contained in:
parent
f933cd0d32
commit
201e6510f8
10 changed files with 272 additions and 135 deletions
|
|
@ -30,7 +30,7 @@ import extract_otp_secret_keys
|
|||
|
||||
class TestExtract(unittest.TestCase):
|
||||
|
||||
def test_extract_csv(self):
|
||||
def test_extract_csv(self) -> None:
|
||||
extract_otp_secret_keys.main(['-q', '-c', 'test_example_output.csv', 'example_export.txt'])
|
||||
|
||||
expected_csv = read_csv('example_output.csv')
|
||||
|
|
@ -38,7 +38,7 @@ class TestExtract(unittest.TestCase):
|
|||
|
||||
self.assertEqual(actual_csv, expected_csv)
|
||||
|
||||
def test_extract_json(self):
|
||||
def test_extract_json(self) -> None:
|
||||
extract_otp_secret_keys.main(['-q', '-j', 'test_example_output.json', 'example_export.txt'])
|
||||
|
||||
expected_json = read_json('example_output.json')
|
||||
|
|
@ -46,7 +46,7 @@ class TestExtract(unittest.TestCase):
|
|||
|
||||
self.assertEqual(actual_json, expected_json)
|
||||
|
||||
def test_extract_stdout_1(self):
|
||||
def test_extract_stdout_1(self) -> None:
|
||||
with Capturing() as output:
|
||||
extract_otp_secret_keys.main(['example_export.txt'])
|
||||
|
||||
|
|
@ -82,7 +82,7 @@ class TestExtract(unittest.TestCase):
|
|||
self.assertEqual(output, expected_output)
|
||||
|
||||
# Ref for capturing https://stackoverflow.com/a/40984270
|
||||
def test_extract_stdout_2(self):
|
||||
def test_extract_stdout_2(self) -> None:
|
||||
out = io.StringIO()
|
||||
with redirect_stdout(out):
|
||||
extract_otp_secret_keys.main(['example_export.txt'])
|
||||
|
|
@ -118,7 +118,7 @@ Type: totp
|
|||
'''
|
||||
self.assertEqual(actual_output, expected_output)
|
||||
|
||||
def test_extract_not_encoded_plus(self):
|
||||
def test_extract_not_encoded_plus(self) -> None:
|
||||
out = io.StringIO()
|
||||
with redirect_stdout(out):
|
||||
extract_otp_secret_keys.main(['test/test_plus_problem_export.txt'])
|
||||
|
|
@ -147,7 +147,7 @@ Type: totp
|
|||
'''
|
||||
self.assertEqual(actual_output, expected_output)
|
||||
|
||||
def test_extract_printqr(self):
|
||||
def test_extract_printqr(self) -> None:
|
||||
out = io.StringIO()
|
||||
with redirect_stdout(out):
|
||||
extract_otp_secret_keys.main(['-p', 'example_export.txt'])
|
||||
|
|
@ -157,7 +157,7 @@ Type: totp
|
|||
|
||||
self.assertEqual(actual_output, expected_output)
|
||||
|
||||
def test_extract_saveqr(self):
|
||||
def test_extract_saveqr(self) -> None:
|
||||
extract_otp_secret_keys.main(['-q', '-s', 'testout/qr/', 'example_export.txt'])
|
||||
|
||||
self.assertTrue(os.path.isfile('testout/qr/1-piraspberrypi-raspberrypi.png'))
|
||||
|
|
@ -165,7 +165,7 @@ Type: totp
|
|||
self.assertTrue(os.path.isfile('testout/qr/3-piraspberrypi.png'))
|
||||
self.assertTrue(os.path.isfile('testout/qr/4-piraspberrypi-raspberrypi.png'))
|
||||
|
||||
def test_extract_verbose(self):
|
||||
def test_extract_verbose(self) -> None:
|
||||
if sys.implementation.name == 'pypy': self.skipTest("Encoding problems in verbose mode in pypy.")
|
||||
out = io.StringIO()
|
||||
with redirect_stdout(out):
|
||||
|
|
@ -176,7 +176,7 @@ Type: totp
|
|||
|
||||
self.assertEqual(actual_output, expected_output)
|
||||
|
||||
def test_extract_debug(self):
|
||||
def test_extract_debug(self) -> None:
|
||||
out = io.StringIO()
|
||||
with redirect_stdout(out):
|
||||
extract_otp_secret_keys.main(['-vvv', 'example_export.txt'])
|
||||
|
|
@ -187,7 +187,7 @@ Type: totp
|
|||
self.assertGreater(len(actual_output), len(expected_stdout))
|
||||
self.assertTrue("DEBUG: " in actual_output)
|
||||
|
||||
def test_extract_help_1(self):
|
||||
def test_extract_help_1(self) -> None:
|
||||
out = io.StringIO()
|
||||
with redirect_stdout(out):
|
||||
try:
|
||||
|
|
@ -201,7 +201,7 @@ Type: totp
|
|||
self.assertGreater(len(actual_output), 0)
|
||||
self.assertTrue("-h, --help" in actual_output and "--verbose, -v" in actual_output)
|
||||
|
||||
def test_extract_help_2(self):
|
||||
def test_extract_help_2(self) -> None:
|
||||
out = io.StringIO()
|
||||
with redirect_stdout(out):
|
||||
with self.assertRaises(SystemExit) as context:
|
||||
|
|
@ -213,7 +213,7 @@ Type: totp
|
|||
self.assertTrue("-h, --help" in actual_output and "--verbose, -v" in actual_output)
|
||||
self.assertEqual(context.exception.code, 0)
|
||||
|
||||
def test_extract_help_3(self):
|
||||
def test_extract_help_3(self) -> None:
|
||||
with Capturing() as actual_output:
|
||||
with self.assertRaises(SystemExit) as context:
|
||||
extract_otp_secret_keys.main(['-h'])
|
||||
|
|
@ -222,13 +222,13 @@ Type: totp
|
|||
self.assertTrue("-h, --help" in "\n".join(actual_output) and "--verbose, -v" in "\n".join(actual_output))
|
||||
self.assertEqual(context.exception.code, 0)
|
||||
|
||||
def setUp(self):
|
||||
def setUp(self) -> None:
|
||||
self.cleanup()
|
||||
|
||||
def tearDown(self):
|
||||
def tearDown(self) -> None:
|
||||
self.cleanup()
|
||||
|
||||
def cleanup(self):
|
||||
def cleanup(self) -> None:
|
||||
remove_file('test_example_output.csv')
|
||||
remove_file('test_example_output.json')
|
||||
remove_dir_with_files('testout/')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue