Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change unit tests to use pytest #29

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .github/workflows/unittests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,5 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install -e .[test]
- name: Test with unittest
run: |
python -m unittest discover test
- name: Test with pytest
run: pytest
2 changes: 1 addition & 1 deletion anonipy/anonymize/strategies/masking.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def __init__(self, substitute_label: str = "*", *args, **kwargs):
"""

super().__init__(*args, **kwargs)
self.substitute_label = substitute_label
self.substitute_label = substitute_label or "*"

def anonymize(
self, text: str, entities: List[Entity], *args, **kwargs
Expand Down
2 changes: 1 addition & 1 deletion anonipy/anonymize/strategies/redaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def __init__(self, substitute_label: str = "[REDACTED]", *args, **kwargs) -> Non
"""

super().__init__(*args, **kwargs)
self.substitute_label = substitute_label
self.substitute_label = substitute_label or "[REDACTED]"

def anonymize(
self, text: str, entities: List[Entity], *args, **kwargs
Expand Down
9 changes: 6 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ build-backend = 'setuptools.build_meta'
[project]
name = "anonipy"
description = "The data anonymization package"
authors=[{ name = "Erik Novak" }]
authors=[
{ name = "Erik Novak" },
{ name = "Nina Kokalj" }
]
maintainers = [{ name = "Erik Novak" }]
readme = "README.md"
license = { file = "LICENSE" }
Expand Down Expand Up @@ -36,8 +39,8 @@ dev = [
"mkdocstrings[python]",
]
test = [
"coverage",
"nbmake",
"pytest",
"pytest-cov",
]
all = ["anonipy[dev,test]"]

Expand Down
16 changes: 4 additions & 12 deletions test/test_anonymize.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import unittest

from anonipy.anonymize import anonymize

# =====================================
Expand Down Expand Up @@ -30,18 +28,12 @@
},
]


# =====================================
# Test Anonymize
# =====================================


class TestAnonymize(unittest.TestCase):
def test_anonymize(self):
anonymized_text, replacements = anonymize(test_text, test_replacements)
self.assertEqual(anonymized_text, test_text_anonymized)
self.assertEqual(replacements, test_replacements)


if __name__ == "__main__":
unittest.main()
def test_anonymize():
anonymized_text, replacements = anonymize(test_text, test_replacements)
assert anonymized_text == test_text_anonymized
assert replacements == test_replacements
74 changes: 33 additions & 41 deletions test/test_entity.py
Original file line number Diff line number Diff line change
@@ -1,48 +1,40 @@
import unittest

from anonipy.definitions import Entity


# =====================================
# Test Entity
# =====================================


class TestEntity(unittest.TestCase):

def test_init_default(self):
entity = Entity(
text="test",
label="test",
start_index=0,
end_index=4,
)
self.assertEqual(entity.text, "test")
self.assertEqual(entity.label, "test")
self.assertEqual(entity.start_index, 0)
self.assertEqual(entity.end_index, 4)
self.assertEqual(entity.score, 1.0)
self.assertEqual(entity.type, None)
self.assertEqual(entity.regex, ".*")

def test_init_custom(self):
entity = Entity(
text="test",
label="test",
start_index=0,
end_index=4,
score=0.89,
type="test",
regex="test",
)
self.assertEqual(entity.text, "test")
self.assertEqual(entity.label, "test")
self.assertEqual(entity.start_index, 0)
self.assertEqual(entity.end_index, 4)
self.assertEqual(entity.score, 0.89)
self.assertEqual(entity.type, "test")
self.assertEqual(entity.regex, "test")


if __name__ == "__main__":
unittest.main()
def test_init_default():
entity = Entity(
text="test",
label="test",
start_index=0,
end_index=4,
)
assert entity.text == "test"
assert entity.label == "test"
assert entity.start_index == 0
assert entity.end_index == 4
assert entity.score == 1.0
assert entity.type is None
assert entity.regex == ".*"


def test_init_custom():
entity = Entity(
text="test",
label="test",
start_index=0,
end_index=4,
score=0.89,
type="test",
regex="test",
)
assert entity.text == "test"
assert entity.label == "test"
assert entity.start_index == 0
assert entity.end_index == 4
assert entity.score == 0.89
assert entity.type == "test"
assert entity.regex == "test"
Loading
Loading