Skip to content

Commit

Permalink
platform independent tests
Browse files Browse the repository at this point in the history
  • Loading branch information
andgineer committed Mar 28, 2024
1 parent 96764b5 commit 38b185d
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions tests/test_bitwarden_import_msecure.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@ def test_version():
assert __version__


def compare_files(file_path1, file_path2):
"""Compare the content of two files, abstracting away platform differences in newline characters."""
with open(file_path1, 'r', newline=None, encoding='utf-8') as f1, open(file_path2, 'r', newline=None,
encoding='utf-8') as f2:
lines1 = f1.readlines()
lines2 = f2.readlines()

lines1 = [line.replace('\r\n', '\n').replace('\r', '\n') for line in lines1]
lines2 = [line.replace('\r\n', '\n').replace('\r', '\n') for line in lines2]
return lines1 == lines2


def test_bitwarden_import_msecure_default_output(tmpdir, msecure_export, bitwarden_file):
input_file = tmpdir.join("input.csv")
input_file.write(msecure_export)
Expand All @@ -20,7 +32,7 @@ def test_bitwarden_import_msecure_default_output(tmpdir, msecure_export, bitward
output_file = tmpdir.join("bitwarden.csv")

# bitwarden_file.write_text(output_file.read_text(encoding="utf8")) # uncomment to refresh the expected output
assert output_file.read() == bitwarden_file.read_text()
assert compare_files(output_file, bitwarden_file)


def test_bitwarden_import_msecure_note_mode_default_output(tmpdir, msecure_export, bitwarden_notes_file):
Expand All @@ -34,7 +46,7 @@ def test_bitwarden_import_msecure_note_mode_default_output(tmpdir, msecure_expor
output_file = tmpdir.join("bitwarden.csv")

# bitwarden_notes_file.write_text(output_file.read_text(encoding="utf8")) # uncomment to refresh the expected output
assert output_file.read() == bitwarden_notes_file.read_text()
assert compare_files(output_file, bitwarden_notes_file)


def test_bitwarden_import_msecure_existing_output_file(tmpdir, msecure_export, bitwarden_file):
Expand Down Expand Up @@ -64,5 +76,5 @@ def test_bitwarden_import_msecure_to_output_file(tmpdir, msecure_export, bitward
result = runner.invoke(bitwarden_import_msecure, [str(input_file), str(output_file), "--force"])
assert result.exit_code == 0

assert output_file.read() == bitwarden_file.read_text()
assert compare_files(output_file, bitwarden_file)
assert input_file.read() == msecure_export # Ensure input file remains unchanged

0 comments on commit 38b185d

Please sign in to comment.