import unittest
import pytest
from old_password import old_password

import csv
import re


@pytest.mark.parametrize("password,expected_hash", [
    (None, None),
    ("", ""),
    ("a", "60671c896665c3fa"),
    ("abc", "7cd2b5942be28759"),
    ("ä", "0751368d49315f7f"),
])
def test_old_password(password, expected_hash):
    assert old_password(password) == expected_hash


def test_password_with_space():
    """
    spaces in password are skipped
    """

    assert old_password("pass word") == old_password("password")


def test_password_with_tab():
    """
    tabs in password are skipped
    """

    assert old_password("pass\tword") == old_password("password")


def test_password_from_testdata():
    with open("../testdata.csv", "r") as file:
        for line in file:
            line = line.strip()
            password, expected_hash = line.split(";")
            hash = old_password(password)

            assert hash == expected_hash, "password: %s" % password

[((9, 1, 15, 2), 'pytest.mark.parametrize', 'pytest.mark.parametrize', ({(9, 25, 9, 49): '"""password,expected_hash"""', (9, 51, 15, 1): "[(None, None), ('', ''), ('a', '60671c896665c3fa'), ('abc',\n    '7cd2b5942be28759'), ('ä', '0751368d49315f7f')]"}, {}), "('password,expected_hash', [(None, None), ('', ''),\n    ('a', '60671c896665c3fa'), ('abc', '7cd2b5942be28759'), ('ä',\n    '0751368d49315f7f')])", False, 'import pytest\n'), ((17, 11, 17, 33), 'old_password.old_password', 'old_password', ({(17, 24, 17, 32): 'password'}, {}), '(password)', False, 'from old_password import old_password\n'), ((25, 11, 25, 36), 'old_password.old_password', 'old_password', ({(25, 24, 25, 35): '"""pass word"""'}, {}), "('pass word')", False, 'from old_password import old_password\n'), ((25, 40, 25, 64), 'old_password.old_password', 'old_password', ({(25, 53, 25, 63): '"""password"""'}, {}), "('password')", False, 'from old_password import old_password\n'), ((33, 11, 33, 37), 'old_password.old_password', 'old_password', ({(33, 24, 33, 36): '"""pass\tword"""'}, {}), "('pass\\tword')", False, 'from old_password import old_password\n'), ((33, 41, 33, 65), 'old_password.old_password', 'old_password', ({(33, 54, 33, 64): '"""password"""'}, {}), "('password')", False, 'from old_password import old_password\n'), ((41, 19, 41, 41), 'old_password.old_password', 'old_password', ({(41, 32, 41, 40): 'password'}, {}), '(password)', False, 'from old_password import old_password\n')]