25-test_pseudonymizer.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. # for py.test
  2. import pseudonymizer as psd
  3. mynames = dict(personnames=["A X", "B Y"])
  4. def test_MultiPseudonymizer():
  5. mypsd = psd.MultiPseudonymizer(pseudonymsource=psd.DictPseudonymsource(mynames))
  6. assert(mypsd.pseudonym("Lutz Prechelt", "personnames") == "A X")
  7. assert(mypsd.pseudonym("Frank Müller", "personnames") == "B Y")
  8. def test_Pseudonymizer_assemble_parts():
  9. mympsd = psd.MultiPseudonymizer(pseudonymsource=psd.DictPseudonymsource(mynames))
  10. mypsd = mympsd.pseudonymizer("personnames")
  11. assert list(map(mypsd.pseudonym, range(12))) == [
  12. "A X", "B Y", "A Y", "B X",
  13. "A X2", "B Y2", "A Y2", "B X2",
  14. "A X3", "B Y3", "A Y3", "B X3",
  15. ]
  16. def test_Pseudonymizer_noblanks56():
  17. mypsd56 = psd.Pseudonymizer(["abxyz", "ABCXYZ"], "personnames")
  18. assert list(map(mypsd56.pseudonym, range(4))) == [
  19. "abxyz", "ABCXYZ", "abXYZ", "ABCxyz",
  20. ]
  21. def test_Pseudonymizer_noblanks12():
  22. mypsd12 = psd.Pseudonymizer(["a", "AZ"], "personnames")
  23. assert list(map(mypsd12.pseudonym, range(4))) == [
  24. "a", "AZ", "Z", "Aa",
  25. ]
  26. def test_Pseudonymizer_noblanks0():
  27. mypsd0 = psd.Pseudonymizer([""], "personnames")
  28. assert list(map(mypsd0.pseudonym, range(3))) == [
  29. "", "2", "3",
  30. ]
  31. def test_Pseudonymizer_leadingtrailingblank():
  32. mypsdlb = psd.Pseudonymizer([" AB", "abc "], "personnames")
  33. assert list(map(mypsdlb.pseudonym, range(4))) == [
  34. " AB", "abc ", " c ", "abAB"
  35. ]
  36. def test_Pseudonymizer_findmiddlefront():
  37. mypsdtb = psd.Pseudonymizer(["AB XYZ", "abc xyz"], "personnames")
  38. assert list(map(mypsdtb.pseudonym, range(4))) == [
  39. "AB XYZ", "abc xyz", "AB xyz", "abc XYZ"
  40. ]
  41. def test_Pseudonymizer_findmiddleback():
  42. mypsdtb = psd.Pseudonymizer(["ABC XYZ", "abc yz"], "personnames")
  43. assert list(map(mypsdtb.pseudonym, range(4))) == [
  44. "ABC XYZ", "abc yz", "ABC yz", "abc XYZ"
  45. ]
  46. def test_Pseudonymizer_findmiddleback():
  47. long1f = "one-but-really-long-in-comparison-to-the-rest-here "
  48. long1b = "Two Three"
  49. long4f = "one two three "
  50. long4b = "and-then-finally-four-but-very-late-indeed-to-be-cut-not-really-in-the-middle"
  51. mypsdtb = psd.Pseudonymizer([long1f+long1b, long4f+long4b], "personnames")
  52. assert list(map(mypsdtb.pseudonym, range(4))) == [
  53. long1f+long1b, long4f+long4b, long1f+long4b, long4f+long1b
  54. ]