Skip to content

Commit

Permalink
test(multiple) : adding tests to the main
Browse files Browse the repository at this point in the history
* build: rename package name and pyproject toml

* docs: modified name in license

* 11 modify the module name from dcm anon to dcm anon (#17)

* fix(modulename): update to dcm_anon

* added a dummy test to ci pipeline

* test: Added stubs for missing tests

* refactor: Modified date and time from datetime more library based than using string manipulation

* test: added tests for datetime after modifying datetime but tests dont run on local

* test: added type annotation

* build: added dicom_Csv and corrected imports tests now run

* test: added tests for hash and datetime

* test: added tests for utils

* build: rename package name and pyproject toml

* docs: modified name in license

* 11 modify the module name from dcm anon to dcm anon (#17)

* fix(modulename): update to dcm_anon

* added a dummy test to ci pipeline

* test: Added stubs for missing tests

* refactor: Modified date and time from datetime more library based than using string manipulation

* test: added tests for datetime after modifying datetime but tests dont run on local

* test: added type annotation

* build: added dicom_Csv and corrected imports tests now run

* test: added tests for hash and datetime

* refactor: Made relative imports

* test: added tests for hash and datetime

* build: rename package name and pyproject toml

* docs: modified name in license

* 11 modify the module name from dcm anon to dcm anon (#17)

* fix(modulename): update to dcm_anon

* added a dummy test to ci pipeline

* test: Added stubs for missing tests

* refactor: Modified date and time from datetime more library based than using string manipulation

* test: added tests for datetime after modifying datetime but tests dont run on local

* test: added type annotation

* build: added dicom_Csv and corrected imports tests now run

* test: added tests for hash and datetime

* refactor: Made relative imports

* refactor: made change to datetime

* test: added tests for datetime

* test: added tests for utils

* build: rename package name and pyproject toml

* docs: modified name in license

* 11 modify the module name from dcm anon to dcm anon (#17)

* fix(modulename): update to dcm_anon

* added a dummy test to ci pipeline

* test: Added stubs for missing tests

* refactor: Modified date and time from datetime more library based than using string manipulation

* test: added tests for datetime after modifying datetime but tests dont run on local

* test: added type annotation

* build: added dicom_Csv and corrected imports tests now run

* test: added tests for hash and datetime

* test: added tests for hash and datetime

* build: rename package name and pyproject toml

* docs: modified name in license

* 11 modify the module name from dcm anon to dcm anon (#17)

* fix(modulename): update to dcm_anon

* added a dummy test to ci pipeline

* test: Added stubs for missing tests

* refactor: Modified date and time from datetime more library based than using string manipulation

* test: added tests for datetime after modifying datetime but tests dont run on local

* test: added type annotation

* build: added dicom_Csv and corrected imports tests now run

* test: added tests for hash and datetime

* refactor: Made relative imports

* changed datetime (#21)

* build: rename package name and pyproject toml

* docs: modified name in license

* test: Added stubs for missing tests

* refactor: Modified date and time from datetime more library based than using string manipulation

* test: added tests for datetime after modifying datetime but tests dont run on local

* test: added type annotation

* build: added dicom_Csv and corrected imports tests now run

* test: added tests for hash and datetime

* refactor: Made relative imports

* refactor: made change to datetime

* test: added test stubs for dcm.py

* test: Added test for reading dicom

---------

Co-authored-by: Abhijeet Parida <[email protected]>
  • Loading branch information
AbinavRavi and a-parida12 authored Jan 31, 2024
1 parent 88123ec commit a6e0e9d
Show file tree
Hide file tree
Showing 18 changed files with 297 additions and 25 deletions.
Binary file added .DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion .github/workflows/build-doc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:

- name: Build Doc ✅
run: |
poetry run pdoc --html -o build dcm-anon
poetry run pdoc --html -o build dcm_anon
- name: Deploy 🚀
uses: JamesIves/github-pages-deploy-action@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:

env:
PYTHON_VERSION: "3.8.15"
PROJECT_FOLDER: dcm-anon
PROJECT_FOLDER: dcm_anon
TEST_FOLDER: tests

jobs:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on: [push]

env:
PYTHON_VERSION: "3.8.15"
PROJECT_FOLDER: dcm-anon
PROJECT_FOLDER: dcm_anon
TEST_FOLDER: tests
COVERAGE_LIMIT: 0

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pip install dcm_anon
To the check the setup, simply check the version number of the `dcm-anon` package by

```bash
python -c 'import dcm-anon; print(dcm_anon.__version__)'
python -c 'import dcm_anon; print(dcm_anon.__version__)'
```

## Usage
Expand Down
2 changes: 1 addition & 1 deletion dcm_anon/anonimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import tqdm
import os
import pydicom
from utils.dcm import check_valid_dcm
from .utils.dcm import check_valid_dcm
import glob


Expand Down
8 changes: 4 additions & 4 deletions dcm_anon/base.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from abc import ABC, abstractmethod
from utils.datetime import get_date, get_datetime, get_time
from utils.dcm import bare_bones_ui
from utils.hash import get_digits, get_non_digits, encrypt_string
from utils.tags import anon_tags
from .utils.datetime import get_date, get_datetime, get_time
from .utils.dcm import bare_bones_ui
from .utils.hash import get_digits, get_non_digits, encrypt_string
from .utils.tags import anon_tags
from pydicom.dataelem import DataElement


Expand Down
12 changes: 6 additions & 6 deletions dcm_anon/utils/datetime.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import re
import string
import datetime


Expand All @@ -9,8 +7,8 @@ def get_datetime() -> str:
Returns:
str: datetime
"""
x = str(datetime.datetime.now()).replace(" ", "")
return re.sub("[%s]" % re.escape(string.punctuation), "", x)[:14]
dt = str(datetime.datetime.now().strftime("%Y%m%d%H%M%S"))
return dt


def get_date() -> str:
Expand All @@ -19,7 +17,8 @@ def get_date() -> str:
Returns:
str: date
"""
return get_datetime()[:8]
date = str(datetime.datetime.now().strftime("%Y%m%d"))
return date


def get_time() -> str:
Expand All @@ -28,4 +27,5 @@ def get_time() -> str:
Returns:
str: time
"""
return get_datetime()[8:]
time = str(datetime.datetime.now().strftime("%H%M%S"))
return time
203 changes: 201 additions & 2 deletions poetry.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ keywords = ["dicom anonimization", "anonimized-data", "dicom", "dcm", "GDPR", "H
[tool.poetry.dependencies]
python = "^3.8"
pydicom = "^2.3.0"
dicom-csv = "^0.2.8"

[tool.poetry.group.dev.dependencies]
pytest = "^7.3.1"
Expand Down
Binary file added tests/.DS_Store
Binary file not shown.
3 changes: 2 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# add root-dir to sys path for tests
import sys
import pytest
from os.path import abspath
from os.path import dirname as d

parent_dir = f"{d(d(abspath(__file__)))}"
sys.path.append(parent_dir)

print(parent_dir)
Binary file added tests/data/.DS_Store
Binary file not shown.
Binary file added tests/data/test1
Binary file not shown.
Binary file added tests/data/test2
Binary file not shown.
Empty file added tests/data/test_dcm.txt
Empty file.
3 changes: 2 additions & 1 deletion tests/pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ junit_family=xunit2
; log_cli_format = %(asctime)s [%(name)s:%(levelname)s] %(message)s (%(filename)s:%(lineno)s)
; log_cli_date_format=%Y-%m-%d %H:%M:%S
markers =
base: only for dev testing not ci (deselect with '-m "not base"')
base: only for dev testing not ci (deselect with '-m "not base"')
utils: utils module (deselect with '-m not utils')
82 changes: 76 additions & 6 deletions tests/test_00_utils.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,79 @@
# import pytest
import pytest
from dcm_anon.utils.datetime import get_datetime, get_date, get_time
from dcm_anon.utils.hash import encrypt_string, get_digits, get_non_digits
from dcm_anon.utils.dcm import check_valid_dcm # , bare_bones_ui, get_dicom_csv

# from hapy_pypi import bool_val

# @pytest.mark.base
# def test_00_1_base_test():
# assert type(bool_val) == bool
# assert bool_val == True
@pytest.fixture
def tests_data():
yield "./tests/data/"


@pytest.mark.utils
def test_get_datetime() -> None:
dt_string = get_datetime()
assert type(dt_string) == str
assert len(dt_string) == 14


@pytest.mark.utils
def test_get_date() -> None:
date = get_date()
assert type(date) == str
assert len(date) == 8


@pytest.mark.utils
def test_get_time() -> None:
time = get_time()
assert type(time) == str
assert len(time) == 6


@pytest.mark.utils
def test_encrypt_string() -> None:
test_string = "test_string"
hash = encrypt_string(test_string)
hex_value = "4b641e9a923d1ea57e18fe41dcb543e2c4005c41ff210864a710b0fbb2654c11"
assert hash == hex_value


@pytest.mark.utils
def test_get_digits() -> None:
test_string = "1a2b3c"
op = get_digits(test_string)
assert op == "123"
assert type(op) == str


@pytest.mark.utils
def test_get_non_digits() -> None:
test_string = "1a2b3c"
op = get_non_digits(test_string)
assert op == "abc"
assert type(op) == str


@pytest.mark.utils
def test_check_valid_dcm(tests_data):
dicom_file = tests_data + "test1"
assert check_valid_dcm(dicom_file) is True

dicom_file = tests_data + "test2"
assert check_valid_dcm(dicom_file) is True


@pytest.mark.utils
def test_check_invalid_dcm(tests_data):
file = tests_data + "test_dcm.txt"
assert check_valid_dcm(file) is False


@pytest.mark.utils
def test_bare_bones_ui():
pass


@pytest.mark.utils
def test_get_dicom_csv():
pass

0 comments on commit a6e0e9d

Please sign in to comment.