Skip to content

Commit 72c9a99

Browse files
authored
Merge pull request #29 from brootware/dev
Dev
2 parents 0553ad3 + 252d7ff commit 72c9a99

File tree

6 files changed

+54
-19
lines changed

6 files changed

+54
-19
lines changed
Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
# This workflow will install Python dependencies, run tests and lint with a single version of Python
2-
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
3-
4-
name: "pylint"
1+
name: "CI"
52

63
on:
74
push:
8-
branches: [main]
5+
branches: [dev]
96
pull_request:
107
branches: [main]
118

@@ -30,8 +27,9 @@ jobs:
3027
run: |
3128
python -m pip install --upgrade pip
3229
python -m pip install --upgrade poetry
33-
pip install flake8 pytest
30+
pip install flake8 pytest nltk numpy
3431
poetry install
32+
python tools/install_nltk_popular.py
3533
3634
- name: Lint with flake8
3735
run: |
@@ -40,6 +38,10 @@ jobs:
4038
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
4139
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
4240
41+
- name: Test with pytest
42+
run: |
43+
pytest
44+
4345
# - name: Build and push Docker Image
4446
# uses: mr-smithers-excellent/docker-build-push@v5
4547
# with:

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<a href="https://twitter.com/brootware"><img src="https://img.shields.io/twitter/follow/brootware?style=social" alt="Twitter Follow"></a>
1515
<img alt="PyPI - Python Version" src="https://img.shields.io/pypi/pyversions/pyredactkit"> <img alt="PyPI" src="https://img.shields.io/pypi/v/pyredactkit">
1616
<a href="https://sonarcloud.io/summary/new_code?id=brootware_PyRedactKit"><img src="https://sonarcloud.io/api/project_badges/measure?project=brootware_PyRedactKit&metric=alert_status" alt="reliability rating"></a>
17-
<img alt="GitHub Workflow Status" src="https://img.shields.io/github/workflow/status/brootware/pyredactkit/pylint?label=pylint">
17+
<img alt="GitHub Workflow Status" src="https://img.shields.io/github/workflow/status/brootware/pyredactkit/CI?label=CI&branch=dev">
1818
</p>
1919

2020
## Features

test/test_redact.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,29 +43,32 @@
4343
mask_names = "\u2588" * 15
4444
count_names = 4
4545

46+
4647
@pytest.fixture
47-
def obj():
48+
def redactor_obj():
4849
return Redactor()
4950

5051

51-
def test_check_python_file(obj):
52-
assert obj.check_file_type(
52+
def test_check_python_file(redactor_obj):
53+
assert redactor_obj.check_file_type(
5354
__file__) == 'text/x-python', 'Failed python file check'
5455

5556

56-
def test_number_of_allowed_types(obj):
57-
assert len(obj.get_allowed_files()
57+
def test_number_of_allowed_types(redactor_obj):
58+
assert len(redactor_obj.get_allowed_files()
5859
) == 10, 'Number of allowed tests does not match expected'
5960

6061

61-
def test_current_file_is_allowed(obj):
62-
assert obj.allowed_file(__file__), f'{__file__} should be allowed'
62+
def test_current_file_is_allowed(redactor_obj):
63+
assert redactor_obj.allowed_file(__file__), f'{__file__} should be allowed'
6364

6465

65-
def test_redact_function_should_return_string(obj):
66-
assert type(obj.redact(data)) == str, 'redact function should return string'
66+
def test_valid_option_function_should_return_tuple(redactor_obj):
67+
assert type(redactor_obj.valid_options()
68+
) == tuple, 'redact function should return tuple'
6769

6870

69-
def test_redact_name_function_should_return_string_and_integer(obj):
70-
set1 = (f'{mask_names},{mask_names},{mask_names},{mask_names}',count_names)
71-
assert obj.redact_name(people_names) == set1, 'redact_name function should return masked data and count'
71+
def test_redact_name_function_should_return_string_and_integer(redactor_obj):
72+
set1 = (f'{mask_names},{mask_names},{mask_names},{mask_names}', count_names)
73+
assert redactor_obj.redact_name(
74+
people_names) == set1, 'redact_name function should return masked data and count'

test/test_unredact.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import pytest
2+
from pyredactkit.unredact import Unredactor
3+
from pyredactkit.identifiers import Identifier
4+
5+
key_mapping = {
6+
"2b21e939-abc9-4d06-9c5a-de9bf2aa22b4": "10.10.10.1"}
7+
redacted_text = "My router is : 2b21e939-abc9-4d06-9c5a-de9bf2aa22b4"
8+
unredacted_text = "My router is : 10.10.10.1"
9+
10+
11+
@pytest.fixture
12+
def unredactor_obj():
13+
return Unredactor()
14+
15+
16+
def test_replace_all_function_should_return_unredacted_string(unredactor_obj):
17+
assert unredactor_obj.replace_all(
18+
redacted_text, key_mapping) == unredacted_text, 'replace_all function should return unredacted string'

tools/install_nltk_popular.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env python
2+
import nltk
3+
import ssl
4+
5+
try:
6+
_create_unverified_https_context = ssl._create_unverified_context
7+
except AttributeError:
8+
pass
9+
else:
10+
ssl._create_default_https_context = _create_unverified_https_context
11+
12+
nltk.download('popular')

0 commit comments

Comments
 (0)