diff --git a/dicom-standard/Makefile b/dicom_standard/Makefile similarity index 100% rename from dicom-standard/Makefile rename to dicom_standard/Makefile diff --git a/dicom-standard/__init__.py b/dicom_standard/__init__.py similarity index 100% rename from dicom-standard/__init__.py rename to dicom_standard/__init__.py diff --git a/dicom-standard/dist/.gitignore b/dicom_standard/dist/.gitignore similarity index 100% rename from dicom-standard/dist/.gitignore rename to dicom_standard/dist/.gitignore diff --git a/dicom-standard/extract_attributes.py b/dicom_standard/extract_attributes.py similarity index 91% rename from dicom-standard/extract_attributes.py rename to dicom_standard/extract_attributes.py index 8f6f572..5d341bf 100644 --- a/dicom-standard/extract_attributes.py +++ b/dicom_standard/extract_attributes.py @@ -3,13 +3,14 @@ ''' import sys -import parse_lib as pl -import parse_relations as pr -from table_utils import table_to_dict +from . import parse_lib as pl +from . import parse_relations as pr +from .table_utils import table_to_dict COLUMN_TITLES = ['tag', 'name', 'keyword', 'valueRepresentation', 'valueMultiplicity', 'retired'] ATTR_TABLE_ID = 'table_6-1' + def get_attribute_table(standard): all_tables = standard.find_all('div', class_='table') html_table = pl.find_tdiv_by_id(all_tables, ATTR_TABLE_ID) diff --git a/dicom-standard/extract_ciod_module_data.py b/dicom_standard/extract_ciod_module_data.py similarity index 93% rename from dicom-standard/extract_ciod_module_data.py rename to dicom_standard/extract_ciod_module_data.py index 93256ca..a5706f9 100644 --- a/dicom-standard/extract_ciod_module_data.py +++ b/dicom_standard/extract_ciod_module_data.py @@ -6,14 +6,15 @@ import sys import re -import parse_lib as pl -import parse_relations as pr -from table_utils import expand_spans, table_to_dict, stringify_table, tdiv_to_table_list +from . import parse_lib as pl +from . import parse_relations as pr +from .table_utils import expand_spans, table_to_dict, stringify_table, tdiv_to_table_list CHAPTER_ID = 'chapter_A' TABLE_SUFFIX = re.compile(".*IOD Modules$") COLUMN_TITLES = ['informationEntity', 'module', 'reference_fragment', 'usage'] + def get_ciod_tables(standard): chapter_A_table_divs = pl.all_tdivs_in_chapter(standard, CHAPTER_ID) ciod_table_divs = list(filter(is_valid_ciod_table, chapter_A_table_divs)) @@ -61,6 +62,7 @@ def get_ciod_description(tdiv): except AttributeError: return None + if __name__ == "__main__": standard = pl.parse_html_file(sys.argv[1]) tables, tdivs = get_ciod_tables(standard) diff --git a/dicom-standard/extract_macros.py b/dicom_standard/extract_macros.py similarity index 89% rename from dicom-standard/extract_macros.py rename to dicom_standard/extract_macros.py index ced2f7a..0489980 100644 --- a/dicom-standard/extract_macros.py +++ b/dicom_standard/extract_macros.py @@ -9,10 +9,10 @@ from bs4 import BeautifulSoup, Tag -import parse_lib as pl -import parse_relations as pr -from table_utils import expand_spans, stringify_table, tdiv_to_table_list, TableListType -from macro_utils import get_id_from_link, MetadataTableType +from . import parse_lib as pl +from . import parse_relations as pr +from .table_utils import expand_spans, stringify_table, tdiv_to_table_list, TableListType +from .macro_utils import get_id_from_link, MetadataTableType # Macros and modules require the same metadata and formatting, # so they can share these two functions. diff --git a/dicom-standard/extract_modules_with_attributes.py b/dicom_standard/extract_modules_with_attributes.py similarity index 97% rename from dicom-standard/extract_modules_with_attributes.py rename to dicom_standard/extract_modules_with_attributes.py index 7a985f7..2f5fcd7 100644 --- a/dicom-standard/extract_modules_with_attributes.py +++ b/dicom_standard/extract_modules_with_attributes.py @@ -6,8 +6,8 @@ import sys import re -import parse_lib as pl -import parse_relations as pr +from . import parse_lib as pl +from . import parse_relations as pr from table_utils import expand_spans, table_to_dict, stringify_table, tdiv_to_table_list CHAPTER_ID = 'chapter_C' @@ -15,6 +15,7 @@ COLUMN_TITLES_WITH_TYPE = ['name', 'tag', 'type', 'description'] COLUMN_TITLES_NO_TYPE = ['name', 'tag', 'description'] + def get_module_tables(standard): chapter_C_table_divs = pl.all_tdivs_in_chapter(standard, CHAPTER_ID) module_table_divs = list(filter(is_valid_module_table, chapter_C_table_divs)) @@ -64,6 +65,7 @@ def clean_table_description(description): table_link.string = 'This module ' return description + if __name__ == '__main__': standard = pl.parse_html_file(sys.argv[1]) tables, tdivs = get_module_tables(standard) diff --git a/dicom-standard/extract_sections.py b/dicom_standard/extract_sections.py similarity index 95% rename from dicom-standard/extract_sections.py rename to dicom_standard/extract_sections.py index e1269b0..d42525b 100644 --- a/dicom-standard/extract_sections.py +++ b/dicom_standard/extract_sections.py @@ -1,9 +1,8 @@ import sys import re import os -from bs4 import BeautifulSoup -from parse_lib import parse_html_file, write_pretty_json +from .parse_lib import parse_html_file, write_pretty_json REFERENCED_IDS_RE = re.compile(r'(sect.*)|(figure.*)|(biblio.*)|(table.*)|(note.*)') diff --git a/dicom-standard/hierarchy_utils.py b/dicom_standard/hierarchy_utils.py similarity index 98% rename from dicom-standard/hierarchy_utils.py rename to dicom_standard/hierarchy_utils.py index cd17c0d..fed7c92 100644 --- a/dicom-standard/hierarchy_utils.py +++ b/dicom_standard/hierarchy_utils.py @@ -7,7 +7,8 @@ from bs4 import Tag -import parse_lib as pl +from . import parse_lib as pl + def get_hierarchy_markers(name: str) -> str: clean_name = name.strip().replace('\n', '') diff --git a/dicom-standard/macro_utils.py b/dicom_standard/macro_utils.py similarity index 96% rename from dicom-standard/macro_utils.py rename to dicom_standard/macro_utils.py index 286a9b9..fcde600 100644 --- a/dicom-standard/macro_utils.py +++ b/dicom_standard/macro_utils.py @@ -8,12 +8,12 @@ from bs4 import BeautifulSoup, Tag -import parse_lib as pl -from hierarchy_utils import get_hierarchy_markers +from .hierarchy_utils import get_hierarchy_markers MetadataTableType = Dict[str, Any] MacrosType = Dict[str, MetadataTableType] + def expand_macro_rows(table: Tag, macros: MacrosType) -> List[Dict[str, str]]: # This variable is used to stop an infinite macro reference # loop in the standard at the SR Document Content module. @@ -62,7 +62,7 @@ def flatten_one_layer(nested_element_list: List[List[Any]]) -> List[Any]: def referenced_macro_id_from_include_statement(macro_reference_html: str) -> str: parsed_reference = BeautifulSoup(macro_reference_html, 'html.parser') id_anchor = parsed_reference.find('a', class_='xref') - return id_anchor.get('href')[1:] # Remove the first '#' character + return id_anchor.get('href')[1:] # Remove the first '#' character def get_macros_by_id(macro_id: str, macros: MacrosType, hierarchy_marker: str) -> MetadataTableType: diff --git a/dicom-standard/parse_lib.py b/dicom_standard/parse_lib.py similarity index 99% rename from dicom-standard/parse_lib.py rename to dicom_standard/parse_lib.py index d755bfe..214d753 100644 --- a/dicom-standard/parse_lib.py +++ b/dicom_standard/parse_lib.py @@ -10,7 +10,7 @@ from bs4 import BeautifulSoup, NavigableString, Tag -import parse_relations as pr +from . import parse_relations as pr BASE_DICOM_URL = "http://dicom.nema.org/medical/dicom/current/output/html/" BASE_SHORT_DICOM_SECTION_URL = "http://dicom.nema.org/medical/dicom/current/output/chtml/" @@ -18,6 +18,7 @@ allowed_attributes = ["href", "src", "type", "data", "colspan", "rowspan"] + def parse_html_file(filepath: str) -> BeautifulSoup: with open(filepath, 'r') as html_file: return BeautifulSoup(html_file, 'html.parser') diff --git a/dicom-standard/parse_relations.py b/dicom_standard/parse_relations.py similarity index 99% rename from dicom-standard/parse_relations.py rename to dicom_standard/parse_relations.py index 9b18a01..8b2f228 100644 --- a/dicom-standard/parse_relations.py +++ b/dicom_standard/parse_relations.py @@ -6,6 +6,7 @@ from typing import List from bs4 import Tag + def table_rows(table_div: Tag) -> List[Tag]: return table_div.find('tbody').find_all('tr') diff --git a/dicom-standard/postprocess_mark_references.py b/dicom_standard/postprocess_mark_references.py similarity index 86% rename from dicom-standard/postprocess_mark_references.py rename to dicom_standard/postprocess_mark_references.py index 0a876f2..bdc7764 100644 --- a/dicom-standard/postprocess_mark_references.py +++ b/dicom_standard/postprocess_mark_references.py @@ -7,14 +7,14 @@ from bs4 import BeautifulSoup -import parse_lib as pl +from . import parse_lib as pl -IGNORED_REFERENCES_RE = re.compile(r'(.*ftp.*)|(.*http.*)|(.*part05.*)|(.*chapter.*)|(.*PS3.*)|(.*DCM.*)|(.*glossentry.*)') +IGNORED_REFS_RE = re.compile(r'(.*ftp.*)|(.*http.*)|(.*part05.*)|(.*chapter.*)|(.*PS3.*)|(.*DCM.*)|(.*glossentry.*)') def get_valid_reference_anchors(parsed_html): anchor_tags = parsed_html.find_all('a', href=True) - return [a for a in anchor_tags if not re.match(IGNORED_REFERENCES_RE, a['href'])] + return [a for a in anchor_tags if not re.match(IGNORED_REFS_RE, a['href'])] def record_references_inside_pairs(module_attr_pairs): @@ -37,6 +37,7 @@ def record_reference_in_pair(pair): def finalize_descriptions(pair): pair['description'] = pl.clean_html(pair['description']) + def reference_structure_from_anchor(reference): return { "sourceUrl": reference.get('href'), diff --git a/dicom-standard/postprocess_save_references.py b/dicom_standard/postprocess_save_references.py similarity index 97% rename from dicom-standard/postprocess_save_references.py rename to dicom_standard/postprocess_save_references.py index 327a5e9..bded53e 100644 --- a/dicom-standard/postprocess_save_references.py +++ b/dicom_standard/postprocess_save_references.py @@ -6,8 +6,7 @@ from bs4 import BeautifulSoup -import parse_lib as pl -from macro_utils import flatten_one_layer +from . import parse_lib as pl def find_reference_html_in_sections(pairs, section_listing): diff --git a/dicom-standard/postprocess_update_reference_links.py b/dicom_standard/postprocess_update_reference_links.py similarity index 95% rename from dicom-standard/postprocess_update_reference_links.py rename to dicom_standard/postprocess_update_reference_links.py index 066b7af..7bfb2dc 100644 --- a/dicom-standard/postprocess_update_reference_links.py +++ b/dicom_standard/postprocess_update_reference_links.py @@ -1,6 +1,7 @@ import sys -import parse_lib as pl +from . import parse_lib as pl + def update_sourceurls(module_attr_pairs, references): for pair in module_attr_pairs: diff --git a/dicom-standard/preprocess_modules_with_attributes.py b/dicom_standard/preprocess_modules_with_attributes.py similarity index 92% rename from dicom-standard/preprocess_modules_with_attributes.py rename to dicom_standard/preprocess_modules_with_attributes.py index 67f6100..2a7e6f3 100644 --- a/dicom-standard/preprocess_modules_with_attributes.py +++ b/dicom_standard/preprocess_modules_with_attributes.py @@ -8,11 +8,10 @@ ''' import sys -from bs4 import BeautifulSoup +from . import parse_lib as pl +from .macro_utils import expand_macro_rows +from .hierarchy_utils import record_hierarchy_for_module -import parse_lib as pl -from macro_utils import expand_macro_rows -from hierarchy_utils import record_hierarchy_for_module def expand_all_macros(module_attr_tables, macros): expanded_attribute_lists = [expand_macro_rows(table, macros) @@ -46,7 +45,6 @@ def preprocess_attribute(attr): return cleaned_attribute - def expand_hierarchy(tables): return [record_hierarchy_for_module(table) for table in tables] diff --git a/dicom-standard/process_ciod_module_relationship.py b/dicom_standard/process_ciod_module_relationship.py similarity index 94% rename from dicom-standard/process_ciod_module_relationship.py rename to dicom_standard/process_ciod_module_relationship.py index 2acb5d8..8030998 100644 --- a/dicom-standard/process_ciod_module_relationship.py +++ b/dicom_standard/process_ciod_module_relationship.py @@ -4,14 +4,16 @@ ''' import sys -import parse_lib as pl +from . import parse_lib as pl + def define_all_relationships(ciod_module_list): all_relationships = [] for table in ciod_module_list: ciod = table['name'] modules = table['modules'] - all_relationships.extend([define_ciod_module_relationship(ciod, module) for module in modules]) + all_relationships.extend([define_ciod_module_relationship(ciod, module) + for module in modules]) return all_relationships diff --git a/dicom-standard/process_ciods.py b/dicom_standard/process_ciods.py similarity index 95% rename from dicom-standard/process_ciods.py rename to dicom_standard/process_ciods.py index 912e7bf..180e85f 100644 --- a/dicom-standard/process_ciods.py +++ b/dicom_standard/process_ciods.py @@ -4,7 +4,8 @@ ''' import sys -import parse_lib as pl +from . import parse_lib as pl + def ciods_from_extracted_list(ciod_module_list): ciods = {} diff --git a/dicom-standard/process_module_attribute_relationship.py b/dicom_standard/process_module_attribute_relationship.py similarity index 96% rename from dicom-standard/process_module_attribute_relationship.py rename to dicom_standard/process_module_attribute_relationship.py index 995e57a..8068631 100644 --- a/dicom-standard/process_module_attribute_relationship.py +++ b/dicom_standard/process_module_attribute_relationship.py @@ -1,6 +1,7 @@ import sys -import parse_lib as pl +from . import parse_lib as pl + def module_attr_relationship_table(module_attr_relationship_list): entries = [] diff --git a/dicom-standard/process_modules.py b/dicom_standard/process_modules.py similarity index 95% rename from dicom-standard/process_modules.py rename to dicom_standard/process_modules.py index 80fdc9a..701c22d 100644 --- a/dicom-standard/process_modules.py +++ b/dicom_standard/process_modules.py @@ -4,7 +4,8 @@ ''' import sys -import parse_lib as pl +from . import parse_lib as pl + def modules_from_tables(tables): modules = {} diff --git a/dicom-standard/standard/part03.html b/dicom_standard/standard/part03.html similarity index 100% rename from dicom-standard/standard/part03.html rename to dicom_standard/standard/part03.html diff --git a/dicom-standard/standard/part04.html b/dicom_standard/standard/part04.html similarity index 100% rename from dicom-standard/standard/part04.html rename to dicom_standard/standard/part04.html diff --git a/dicom-standard/standard/part06.html b/dicom_standard/standard/part06.html similarity index 100% rename from dicom-standard/standard/part06.html rename to dicom_standard/standard/part06.html diff --git a/dicom-standard/standard/part15.html b/dicom_standard/standard/part15.html similarity index 100% rename from dicom-standard/standard/part15.html rename to dicom_standard/standard/part15.html diff --git a/dicom-standard/standard/part16.html b/dicom_standard/standard/part16.html similarity index 100% rename from dicom-standard/standard/part16.html rename to dicom_standard/standard/part16.html diff --git a/dicom-standard/standard/part17.html b/dicom_standard/standard/part17.html similarity index 100% rename from dicom-standard/standard/part17.html rename to dicom_standard/standard/part17.html diff --git a/dicom-standard/standard/part18.html b/dicom_standard/standard/part18.html similarity index 100% rename from dicom-standard/standard/part18.html rename to dicom_standard/standard/part18.html diff --git a/dicom-standard/table_utils.py b/dicom_standard/table_utils.py similarity index 94% rename from dicom-standard/table_utils.py rename to dicom_standard/table_utils.py index 753acfb..ecca5ae 100644 --- a/dicom-standard/table_utils.py +++ b/dicom_standard/table_utils.py @@ -6,10 +6,11 @@ from copy import copy from bs4 import Tag -import parse_relations as pr +from . import parse_relations as pr TableListType = List[List[Tag]] + def table_to_dict(table: TableListType, row_names: List[str]) -> List[Dict[str, List[Tag]]]: return [dict(zip(row_names, row)) for row in table] @@ -37,7 +38,7 @@ def expand_rows(table: TableListType) -> TableListType: communicated between each row (the rowspan information). ''' extended_table = [] - row_expansion = [] # Format: [(bs_html_object, row_index)] + row_expansion = [] # Format: [(bs_html_object, row_index)] for row in table: expanded_row, row_expansion = expand_rowspans(row, row_expansion) extended_table.append(expanded_row) @@ -71,7 +72,7 @@ def slide_down(start_idx: int, row: List[Tag], num_slides: int = 1) -> List[Tag] ''' try: sliding_rows = row[start_idx:len(row)] - new_row = row[0:len(row)-len(sliding_rows)] + new_row = row[0:len(row) - len(sliding_rows)] for i in range(num_slides): new_row.append(None) new_row.extend(sliding_rows) @@ -105,7 +106,7 @@ def is_new_rowspan_cell(cell: Tag, idx: int, row_expansion: List[Tuple[Tag, int] def remove_completed_rowspans(row_expansion: List[Tuple[Tag, int]]) -> List[Tuple[Tag, int]]: - return [(cell,idx) for (cell, idx) in row_expansion + return [(cell, idx) for (cell, idx) in row_expansion if has_rowspans_to_expand(cell)] @@ -126,6 +127,6 @@ def expand_cell_colspan(cell: Tag) -> Tag: if colspan_count is not None: colspans = int(colspan_count) cell['colspan'] = 1 - for i in range(colspans-1): + for i in range(colspans - 1): expanded_cell.append(None) return expanded_cell diff --git a/setup.py b/setup.py index 51aecf7..fd20f29 100644 --- a/setup.py +++ b/setup.py @@ -43,7 +43,7 @@ ], extras_require={ - 'dev': [], + 'dev': ['check-manifest'], 'test': ['pytest'], }, diff --git a/tests/end_to_end_test.py b/tests/end_to_end_test.py index 4af9dab..5830526 100644 --- a/tests/end_to_end_test.py +++ b/tests/end_to_end_test.py @@ -2,7 +2,7 @@ import pytest -import parse_lib as pl +import dicom_standard.parse_lib as pl @pytest.fixture(scope='module') @@ -12,27 +12,27 @@ def make_standard(): @pytest.fixture(scope='module') def ciods(make_standard): - return pl.read_json_to_dict('dist/ciods.json') + return pl.read_json_to_dict('standard/ciods.json') @pytest.fixture(scope='module') def modules(make_standard): - return pl.read_json_to_dict('dist/modules.json') + return pl.read_json_to_dict('standard/modules.json') @pytest.fixture(scope='module') def attributes(make_standard): - return pl.read_json_to_dict('dist/attributes.json') + return pl.read_json_to_dict('standard/attributes.json') @pytest.fixture(scope='module') def ciod_module_relationship(make_standard): - return pl.read_json_to_dict('dist/ciod_to_modules.json') + return pl.read_json_to_dict('standard/ciod_to_modules.json') @pytest.fixture(scope='module') def module_attribute_relationship(make_standard): - return pl.read_json_to_dict('dist/module_to_attributes.json') + return pl.read_json_to_dict('standard/module_to_attributes.json') @pytest.mark.endtoend @@ -53,8 +53,8 @@ def test_valid_foreign_keys_module_attribute(module_attribute_relationship, modu def test_vertical_samples_from_standard(ciods, modules, attributes): test_ciod = { "us-multi-frame-image": { - "description":"

\nThe Ultrasound (US) Multi-frame Image Information Object Definition specifies a Multi-frame image that has been created by an ultrasound imaging device.

", - "linkToStandard":"http://dicom.nema.org/medical/dicom/current/output/chtml/part03/sect_A.7.4.html#table_A.7-1", + "description": "

\nThe Ultrasound (US) Multi-frame Image Information Object Definition specifies a Multi-frame image that has been created by an ultrasound imaging device.

", + "linkToStandard": "http://dicom.nema.org/medical/dicom/current/output/chtml/part03/sect_A.7.4.html#table_A.7-1", "name": "US Multi-frame Image", "id": "us-multi-frame-image", } @@ -63,13 +63,13 @@ def test_vertical_samples_from_standard(ciods, modules, attributes): "patient": { "name": "Patient", "id": "patient", - "description":"

\nThis module specifies the Attributes of the Patient that describe and identify the Patient who is the subject of a Study.\n This Module contains Attributes of the patient that are needed for interpretation of the Composite Instances and are common for all studies performed on the patient. It contains Attributes that are also included in the Patient Modules in Section\u00a0C.2.

", - "linkToStandard":"http://dicom.nema.org/medical/dicom/current/output/chtml/part03/sect_C.7.html#table_C.7-1" + "description": "

\nThis module specifies the Attributes of the Patient that describe and identify the Patient who is the subject of a Study.\n This Module contains Attributes of the patient that are needed for interpretation of the Composite Instances and are common for all studies performed on the patient. It contains Attributes that are also included in the Patient Modules in Section\u00a0C.2.

", + "linkToStandard": "http://dicom.nema.org/medical/dicom/current/output/chtml/part03/sect_C.7.html#table_C.7-1" } } test_attribute = { "00100010": { - "tag":"(0010,0010)", + "tag": "(0010,0010)", "retired": False, "keyword": "PatientName", "name": "Patient's Name", @@ -101,70 +101,70 @@ def test_vertical_samples_from_standard(ciods, modules, attributes): @pytest.mark.endtoend -def test_trace_from_attribute_to_ciod(ciods, ciod_module_relationship, - modules, module_attribute_relationship, attributes): +def test_trace_from_attribute_to_ciod(ciods, ciod_module_relationship, modules, + module_attribute_relationship, attributes): attr = { "00080121": { - "name":"Equivalent Code Sequence", + "name": "Equivalent Code Sequence", "retired": False, - "valueMultiplicity":"1", - "keyword":"EquivalentCodeSequence", - "valueRepresentation":"SQ", + "valueMultiplicity": "1", + "keyword": "EquivalentCodeSequence", + "valueRepresentation": "SQ", "tag": "(0008,0121)" } } module_attr = [ { - "module":"patient-study", - "path":"patient-study:00081084:00080121", - "tag":"(0008,0121)", - "type":"3", - "linkToStandard":"http://dicom.nema.org/medical/dicom/current/output/chtml/part03/sect_C.7.2.2.html#table_C.7-4a", - "description":"\n

\nCodes that are considered equivalent by the creating system.

\n

\nOne or more Items are permitted in this Sequence.

\n

\nSee Section\u00a08.9.

\n", - "externalReferences":[ + "module": "patient-study", + "path": "patient-study:00081084:00080121", + "tag": "(0008,0121)", + "type": "3", + "linkToStandard": "http://dicom.nema.org/medical/dicom/current/output/chtml/part03/sect_C.7.2.2.html#table_C.7-4a", + "description": "\n

\nCodes that are considered equivalent by the creating system.

\n

\nOne or more Items are permitted in this Sequence.

\n

\nSee Section\u00a08.9.

\n", + "externalReferences": [ { - "sourceUrl":"http://dicom.nema.org/medical/dicom/current/output/chtml/part03/sect_8.9.html#sect_8.9", + "sourceUrl": "http://dicom.nema.org/medical/dicom/current/output/chtml/part03/sect_8.9.html#sect_8.9", "title": "Section\u00a08.9" }, ] }, { - "module":"patient-study", - "path":"patient-study:00101021:00080121", - "tag":"(0008,0121)", - "type":"3", - "linkToStandard":"http://dicom.nema.org/medical/dicom/current/output/chtml/part03/sect_C.7.2.2.html#table_C.7-4a", - "description":"\n

\nCodes that are considered equivalent by the creating system.

\n

\nOne or more Items are permitted in this Sequence.

\n

\nSee Section\u00a08.9.

\n", - "externalReferences":[ + "module": "patient-study", + "path": "patient-study:00101021:00080121", + "tag": "(0008,0121)", + "type": "3", + "linkToStandard": "http://dicom.nema.org/medical/dicom/current/output/chtml/part03/sect_C.7.2.2.html#table_C.7-4a", + "description": "\n

\nCodes that are considered equivalent by the creating system.

\n

\nOne or more Items are permitted in this Sequence.

\n

\nSee Section\u00a08.9.

\n", + "externalReferences": [ { - "sourceUrl":"http://dicom.nema.org/medical/dicom/current/output/chtml/part03/sect_8.9.html#sect_8.9", + "sourceUrl": "http://dicom.nema.org/medical/dicom/current/output/chtml/part03/sect_8.9.html#sect_8.9", "title": "Section\u00a08.9" }, ] }, ] module = { - "patient-study":{ - "id":"patient-study", - "name":"Patient Study", - "description":"

\nThis module defines Attributes that provide information about the Patient at the time the Study started.

", - "linkToStandard":"http://dicom.nema.org/medical/dicom/current/output/chtml/part03/sect_C.7.2.2.html#table_C.7-4a" + "patient-study": { + "id": "patient-study", + "name": "Patient Study", + "description": "

\nThis module defines Attributes that provide information about the Patient at the time the Study started.

", + "linkToStandard": "http://dicom.nema.org/medical/dicom/current/output/chtml/part03/sect_C.7.2.2.html#table_C.7-4a" }, } ciod_module = [ { - "ciod":"cr-image", - "module":"patient-study", - "usage":"U", + "ciod": "cr-image", + "module": "patient-study", + "usage": "U", "conditionalStatement": None, - "informationEntity":"Study" + "informationEntity": "Study" }, ] ciod = { "cr-image": { - "description":"

\nThe Computed Radiography (CR) Image Information Object Definition specifies an image that has been created by a computed radiography imaging device.

", - "name":"CR Image", - "linkToStandard":"http://dicom.nema.org/medical/dicom/current/output/chtml/part03/sect_A.2.3.html#table_A.2-1", + "description": "

\nThe Computed Radiography (CR) Image Information Object Definition specifies an image that has been created by a computed radiography imaging device.

", + "name": "CR Image", + "linkToStandard": "http://dicom.nema.org/medical/dicom/current/output/chtml/part03/sect_A.2.3.html#table_A.2-1", "id": "cr-image", } } @@ -180,29 +180,29 @@ def test_trace_from_attribute_to_ciod(ciods, ciod_module_relationship, def test_number_of_attribute_appearances(module_attribute_relationship, attributes): module_attr = [ { - "module":"patient-demographic", - "path":"patient-demographic:00100213", - "tag":"(0010,0213)", - "type":"None", - "linkToStandard":"http://dicom.nema.org/medical/dicom/current/output/chtml/part03/sect_C.2.3.html#table_C.2-3", - "description":"\n

\nThe nomenclature used for Strain Description (0010,0212). See Section\u00a0C.7.1.1.1.4.

\n", - "externalReferences":[ + "module": "patient-demographic", + "path": "patient-demographic:00100213", + "tag": "(0010,0213)", + "type": "None", + "linkToStandard": "http://dicom.nema.org/medical/dicom/current/output/chtml/part03/sect_C.2.3.html#table_C.2-3", + "description": "\n

\nThe nomenclature used for Strain Description (0010,0212). See Section\u00a0C.7.1.1.1.4.

\n", + "externalReferences": [ { - "sourceUrl":"http://dicom.nema.org/medical/dicom/current/output/chtml/part03/sect_C.7.html#sect_C.7.1.1.1.4", + "sourceUrl": "http://dicom.nema.org/medical/dicom/current/output/chtml/part03/sect_C.7.html#sect_C.7.1.1.1.4", "title": "Section\u00a0C.7.1.1.1.4" }, ] }, { - "module":"patient", - "path":"patient:00100213", - "tag":"(0010,0213)", - "type":"3", - "linkToStandard":"http://dicom.nema.org/medical/dicom/current/output/chtml/part03/sect_C.7.html#table_C.7-1", - "description":"\n

\nThe nomenclature used for Strain Description (0010,0212). See Section\u00a0C.7.1.1.1.4.

\n", - "externalReferences":[ + "module": "patient", + "path": "patient:00100213", + "tag": "(0010,0213)", + "type": "3", + "linkToStandard": "http://dicom.nema.org/medical/dicom/current/output/chtml/part03/sect_C.7.html#table_C.7-1", + "description": "\n

\nThe nomenclature used for Strain Description (0010,0212). See Section\u00a0C.7.1.1.1.4.

\n", + "externalReferences": [ { - "sourceUrl":"http://dicom.nema.org/medical/dicom/current/output/chtml/part03/sect_C.7.html#sect_C.7.1.1.1.4", + "sourceUrl": "http://dicom.nema.org/medical/dicom/current/output/chtml/part03/sect_C.7.html#sect_C.7.1.1.1.4", "title": "Section\u00a0C.7.1.1.1.4" }, ] @@ -211,11 +211,11 @@ def test_number_of_attribute_appearances(module_attribute_relationship, attribut attrs = { "00100213": { - "name":"Strain Nomenclature", - "retired":False, - "valueMultiplicity":"1", - "keyword":"StrainNomenclature", - "valueRepresentation":"LO", + "name": "Strain Nomenclature", + "retired": False, + "valueMultiplicity": "1", + "keyword": "StrainNomenclature", + "valueRepresentation": "LO", "tag": "(0010,0213)" } } @@ -231,19 +231,19 @@ def test_number_of_attribute_appearances(module_attribute_relationship, attribut def test_number_of_module_appearances(ciods, ciod_module_relationship, modules): module = { "volume-cropping": { - "name":"Volume Cropping", - "linkToStandard":"http://dicom.nema.org/medical/dicom/current/output/chtml/part03/sect_C.11.24.html#table_C.11.24-1", - "description":"

\nThis module contains the attributes of the Volume Cropping Module. This Module limits the spatial extent of inputs in Volumetric Presentation State Input Sequence (0070,1201) that are used.

", + "name": "Volume Cropping", + "linkToStandard": "http://dicom.nema.org/medical/dicom/current/output/chtml/part03/sect_C.11.24.html#table_C.11.24-1", + "description": "

\nThis module contains the attributes of the Volume Cropping Module. This Module limits the spatial extent of inputs in Volumetric Presentation State Input Sequence (0070,1201) that are used.

", "id": "volume-cropping" } } ciod_module = [ { - "informationEntity":"Presentation State", - "module":"volume-cropping", - "usage":"U", - "conditionalStatement":None, - "ciod":"planar-mpr-volumetric-presentation-state", + "informationEntity": "Presentation State", + "module": "volume-cropping", + "usage": "U", + "conditionalStatement": None, + "ciod": "planar-mpr-volumetric-presentation-state", } ] assert module['volume-cropping'] == modules['volume-cropping'] diff --git a/tests/extract_attributes_test.py b/tests/extract_attributes_test.py index 46e8023..c93820c 100644 --- a/tests/extract_attributes_test.py +++ b/tests/extract_attributes_test.py @@ -1,6 +1,6 @@ from bs4 import BeautifulSoup -import extract_attributes as ea +import dicom_standard.extract_attributes as ea example_table = ''' @@ -9,6 +9,7 @@ >>name1', ' >space in front', '>> \nstrange whitespace', '>>>>>>>>>>>>>>>>>>>> Long marker run', 'No markers'] + def test_get_hierarchy_markers(): expected_result = ['>>>', '>', '>>', '>>>>>>>>>>>>>>>>>>>>', ''] results = list(map(h.get_hierarchy_markers, test_names)) diff --git a/tests/macro_utils_test.py b/tests/macro_utils_test.py index 44dd765..3ea6ce1 100644 --- a/tests/macro_utils_test.py +++ b/tests/macro_utils_test.py @@ -1,9 +1,10 @@ -import macro_utils as m +import dicom_standard.macro_utils as m example_include_statement = '''

>> Include Table somemacro

''' + def test_is_macro_row(): example_macro_row = { 'tag': 'None', @@ -39,13 +40,24 @@ def test_update_attribute_hierarchy_markers(): ] assert m.update_attribute_hierarchy_markers(example_attributes, '>>') == expected_attributes + def test_insert_nested_macro(): mock_table = { 'linkToStandard': 'http://somelink#table-id', 'name': 'mock-table', 'attributes': [ - {'name': 'Attribute 1', 'type': 'None', 'tag': '00010001', 'description': 'something' }, - {'name': '>Include Table Otherthing', 'type': 'None', 'tag': 'None', 'description': 'None' } + { + 'name': 'Attribute 1', + 'type': 'None', + 'tag': '00010001', + 'description': 'something' + }, + { + 'name': '>Include Table Otherthing', + 'type': 'None', + 'tag': 'None', + 'description': 'None' + } ] } @@ -54,27 +66,77 @@ def test_insert_nested_macro(): 'linkToStandard': 'http://somelink#somemacro', 'name': 'mock-macro', 'attributes': [ - {'name': 'Attribute 1a', 'type': 'None', 'tag': '00010002', 'description': 'some attribute in a macro'}, - {'name': '>Attribute 1e', 'type': 'None', 'tag': '00010005', 'description': 'some nested attribute in a macro'}, - {'name': '>>Include Table Otherthing2', 'type': 'None', 'tag': 'None', 'description': 'None' } + { + 'name': 'Attribute 1a', + 'type': 'None', + 'tag': '00010002', + 'description': 'some attribute in a macro' + }, + { + 'name': '>Attribute 1e', + 'type': 'None', + 'tag': '00010005', + 'description': 'some nested attribute in a macro' + }, + { + 'name': '>>Include Table Otherthing2', + 'type': 'None', + 'tag': 'None', + 'description': 'None' + } ] }, "somemacro2": { 'linkToStandard': 'http://somelink#somemacro2', 'name': 'mock-macro-2', 'attributes': [ - {'name': 'Attribute 1b', 'type': 'None', 'tag': '00010003', 'description': 'some other attribute in a macro'}, - {'name': '>Attribute 1c', 'type': 'None', 'tag': '00010004', 'description': 'some final attribute in a macro'} + { + 'name': 'Attribute 1b', + 'type': 'None', + 'tag': '00010003', + 'description': 'some other attribute in a macro' + }, + { + 'name': '>Attribute 1c', + 'type': 'None', + 'tag': '00010004', + 'description': 'some final attribute in a macro' + } ] } } expected_attributes = [ - {'name': 'Attribute 1', 'type': 'None', 'tag': '00010001', 'description': 'something' }, - {'name': '>Attribute 1a', 'type': 'None', 'tag': '00010002', 'description': 'some attribute in a macro'}, - {'name': '>>Attribute 1e', 'type': 'None', 'tag': '00010005', 'description': 'some nested attribute in a macro'}, - {'name': '>>>Attribute 1b', 'type': 'None', 'tag': '00010003', 'description': 'some other attribute in a macro'}, - {'name': '>>>>Attribute 1c', 'type': 'None', 'tag': '00010004', 'description': 'some final attribute in a macro'} + { + 'name': 'Attribute 1', + 'type': 'None', + 'tag': '00010001', + 'description': 'something' + }, + { + 'name': '>Attribute 1a', + 'type': 'None', + 'tag': '00010002', + 'description': 'some attribute in a macro' + }, + { + 'name': '>>Attribute 1e', + 'type': 'None', + 'tag': '00010005', + 'description': 'some nested attribute in a macro' + }, + { + 'name': '>>>Attribute 1b', + 'type': 'None', + 'tag': '00010003', + 'description': 'some other attribute in a macro' + }, + { + 'name': '>>>>Attribute 1c', + 'type': 'None', + 'tag': '00010004', + 'description': 'some final attribute in a macro' + } ] assert m.expand_macro_rows(mock_table, mock_macros) == expected_attributes diff --git a/tests/parse_lib_test.py b/tests/parse_lib_test.py index 8a31245..9c962b3 100644 --- a/tests/parse_lib_test.py +++ b/tests/parse_lib_test.py @@ -1,6 +1,5 @@ -from bs4 import BeautifulSoup as bs +import dicom_standard.parse_lib as pl -import parse_lib as pl def test_create_slug(): test_titles = [ diff --git a/tests/process_ciod_module_relations_test.py b/tests/process_ciod_module_relations_test.py index f4c9be3..2ed3646 100644 --- a/tests/process_ciod_module_relations_test.py +++ b/tests/process_ciod_module_relations_test.py @@ -1,6 +1,6 @@ import pytest -from process_ciod_module_relationship import expand_conditional_statement +from dicom_standard.process_ciod_module_relationship import expand_conditional_statement def test_expand_conditional_statement_normal_cases(): diff --git a/tests/process_modules_with_attributes_test.py b/tests/process_modules_with_attributes_test.py index 7dc15cf..b62ae66 100644 --- a/tests/process_modules_with_attributes_test.py +++ b/tests/process_modules_with_attributes_test.py @@ -1,9 +1,20 @@ from bs4 import BeautifulSoup -from parse_lib import remove_attributes_from_html_tags +from dicom_standard.parse_lib import remove_attributes_from_html_tags + def test_remove_attributes_from_tag(): - tag = '

This is an awesome

description
.

' + tag = ''' +

+ This is an + + awesome + +

+ description +
. +

+ ''' html = BeautifulSoup(tag, 'html.parser') top_level_tag = html.find('p') remove_attributes_from_html_tags(top_level_tag) diff --git a/tests/table_utils_test.py b/tests/table_utils_test.py index 29de5f5..321b0e9 100644 --- a/tests/table_utils_test.py +++ b/tests/table_utils_test.py @@ -3,9 +3,10 @@ ''' from bs4 import BeautifulSoup as bs -import table_utils as t +import dicom_standard.table_utils as t import tests.html_snippets as tables + def parsed_html_table(string_table): parsed_html = bs(string_table, 'html.parser') table_tag = parsed_html.find('tbody') diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..9e5259d --- /dev/null +++ b/tox.ini @@ -0,0 +1,20 @@ +[tox] +envlist = py34,py35,py36 + +[testenv] +basepython = + py34: python3.4 + py35: python3.5 + py36: python3.6 +deps = + flake8 + pytest +commands = + python setup.py check -m -s + flake8 . --ignore=E501 + pytest tests + +[flake8] +exclude = .tox,*.egg,build,data +select = E,W,F +max-line-length = 120