mirror of
https://github.com/scito/extract_otp_secret_keys.git
synced 2025-12-06 14:54:57 +01:00
refactor tests, add utils
This commit is contained in:
parent
cf91108c3f
commit
aaef496d4f
3 changed files with 39 additions and 46 deletions
|
|
@ -18,9 +18,7 @@
|
||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import csv
|
from utils import read_csv, read_json, remove_file
|
||||||
import json
|
|
||||||
import os
|
|
||||||
|
|
||||||
import extract_otp_secret_keys
|
import extract_otp_secret_keys
|
||||||
|
|
||||||
|
|
@ -61,23 +59,3 @@ def test_extract_json():
|
||||||
def cleanup():
|
def cleanup():
|
||||||
remove_file('test_example_output.csv')
|
remove_file('test_example_output.csv')
|
||||||
remove_file('test_example_output.json')
|
remove_file('test_example_output.json')
|
||||||
|
|
||||||
|
|
||||||
def remove_file(filename):
|
|
||||||
if os.path.exists(filename): os.remove(filename)
|
|
||||||
|
|
||||||
|
|
||||||
def read_csv(filename):
|
|
||||||
"""Returns a list of lines."""
|
|
||||||
with open(filename, "r") as infile:
|
|
||||||
lines = []
|
|
||||||
reader = csv.reader(infile)
|
|
||||||
for line in reader:
|
|
||||||
lines.append(line)
|
|
||||||
return lines
|
|
||||||
|
|
||||||
|
|
||||||
def read_json(filename):
|
|
||||||
"""Returns a list or a dictionary."""
|
|
||||||
with open(filename, "r") as infile:
|
|
||||||
return json.load(infile)
|
|
||||||
|
|
|
||||||
|
|
@ -19,9 +19,7 @@
|
||||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
import csv
|
from utils import read_csv, read_json, remove_file
|
||||||
import json
|
|
||||||
import os
|
|
||||||
|
|
||||||
import extract_otp_secret_keys
|
import extract_otp_secret_keys
|
||||||
|
|
||||||
|
|
@ -55,25 +53,5 @@ class TestExtract(unittest.TestCase):
|
||||||
remove_file('test_example_output.json')
|
remove_file('test_example_output.json')
|
||||||
|
|
||||||
|
|
||||||
def remove_file(filename):
|
|
||||||
if os.path.exists(filename): os.remove(filename)
|
|
||||||
|
|
||||||
|
|
||||||
def read_csv(filename):
|
|
||||||
"""Returns a list of lines."""
|
|
||||||
with open(filename, "r") as infile:
|
|
||||||
lines = []
|
|
||||||
reader = csv.reader(infile)
|
|
||||||
for line in reader:
|
|
||||||
lines.append(line)
|
|
||||||
return lines
|
|
||||||
|
|
||||||
|
|
||||||
def read_json(filename):
|
|
||||||
"""Returns a list or a dictionary."""
|
|
||||||
with open(filename, "r") as infile:
|
|
||||||
return json.load(infile)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
||||||
37
utils.py
Normal file
37
utils.py
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
# Author: Scito (https://scito.ch)
|
||||||
|
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
import csv
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
|
||||||
|
def remove_file(filename):
|
||||||
|
if os.path.exists(filename): os.remove(filename)
|
||||||
|
|
||||||
|
|
||||||
|
def read_csv(filename):
|
||||||
|
"""Returns a list of lines."""
|
||||||
|
with open(filename, "r") as infile:
|
||||||
|
lines = []
|
||||||
|
reader = csv.reader(infile)
|
||||||
|
for line in reader:
|
||||||
|
lines.append(line)
|
||||||
|
return lines
|
||||||
|
|
||||||
|
|
||||||
|
def read_json(filename):
|
||||||
|
"""Returns a list or a dictionary."""
|
||||||
|
with open(filename, "r") as infile:
|
||||||
|
return json.load(infile)
|
||||||
Loading…
Add table
Add a link
Reference in a new issue