Browse Source

tests: Fix censoring test

feature/fints
Jakub Valenta 1 year ago
parent
commit
fe1295c415
3 changed files with 46 additions and 20 deletions
  1. 4
    2
      account_statement/account_statement.py
  2. 39
    17
      account_statement/tests/test_account_statement.py
  3. 3
    1
      tox.ini

+ 4
- 2
account_statement/account_statement.py View File

@@ -44,19 +44,21 @@ def censor_codes(value: str) -> str:


def censor_names(value: str) -> str:
"""Replace ``value`` with empty string if it seems to be a human name."""
if not value:
return value
if REGEX_CENSOR_NAMES.match(value):
print('Censoring (names) "{}"'.format(value))
print(f'Censoring (names) "{value}"')
return ''
return value


def censor_list(value: str, excl: Sequence[str] = ()) -> str:
"""Replace ``value`` with empty string if it's in list ``excl``."""
if not value:
return value
if value in excl:
print('Censoring (list) "{}"'.format(value))
print(f'Censoring (list) "{value}"')
return ''
return value


+ 39
- 17
account_statement/tests/test_account_statement.py View File

@@ -1,10 +1,13 @@
from unittest import TestCase

from ddt import data, ddt

from account_statement.account_statement import (
censor_codes, censor_list, censor_names,
)


@ddt
class Test(TestCase):

def test_fio_censor_codes(self):
@@ -13,20 +16,39 @@ class Test(TestCase):
'Lorem 789 ipsum'
)

def test_fio_censor_names(self):
with open('_test_censor_names_true.txt') as f:
for line in f:
self.assertEqual(censor_names(line.strip()), '')
with open('_test_censor_names_false.txt') as f:
for line in f:
self.assertEqual(censor_names(line.strip()), line.strip())

def test_fio_censor_list(self):
with open('_test_censor_names_false.txt') as f:
excl = [x.strip() for x in f.readlines()]
with open('_test_censor_names_false.txt') as f:
for line in f:
self.assertEqual(censor_list(line.strip(), excl), '')
with open('_test_censor_names_true.txt') as f:
for line in f:
self.assertEqual(censor_list(line.strip(), excl), line.strip())
@data(
'',
'Jakub Valenta',
'JAKUB VALENTA',
'Ja Valenta',
'Ja VALENTA',
)
def test_censor_names_censored(self, name):
self.assertEqual(censor_names(name), '')

@data(
'',
'Jakub',
'Valenta',
'J Valenta',
'J VALENTA',
)
def test_censor_names_kept(self, name):
self.assertEqual(censor_names(name), name)

@data(
'',
'foo',
)
def test_censor_list_censored(self, name):
excl = ['foo', 'bar']
self.assertEqual(censor_list(name, excl), '')

@data(
'',
'spam',
'BAR',
)
def test_censor_list_kept(self, name):
excl = ['foo', 'bar']
self.assertEqual(censor_list(name, excl), name)

+ 3
- 1
tox.ini View File

@@ -3,7 +3,9 @@ envlist = py37, lint, isort
skip_missing_interpreters = True

[testenv]
deps = pytest
deps =
pytest
ddt
commands = pytest account_statement/tests

[testenv:lint]

Loading…
Cancel
Save