diff --git a/pyproject.toml b/pyproject.toml index 08c5f78..91624c7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "python_tabular" -version = "0.3.2" +version = "0.3.3" authors = [ { name="Curtis Stallings", email="curtisrstallings@gmail.com" }, ] diff --git a/pytabular/culture.py b/pytabular/culture.py index 01de1cc..de1e0de 100644 --- a/pytabular/culture.py +++ b/pytabular/culture.py @@ -2,6 +2,7 @@ """ import logging from object import PyObject, PyObjects +from typing import List logger = logging.getLogger("PyTabular") @@ -19,7 +20,7 @@ def __init__(self, object, model) -> None: self._display.add_row("Culture Name", self._object.Name) self.ObjectTranslations = self.set_translation() - def set_translation(self) -> list[dict]: + def set_translation(self) -> List[dict]: """ Based on the culture, it creates a list of dicts with all the available translations in the file. @@ -42,16 +43,18 @@ def get_translation( By default it will search for the "Caption" object type, due to fact that a Display folder and Description can also have translations. """ - if translations := [ - d - for d in self.ObjectTranslations - if d["object_name"] == object_name - and d["object_type"] == object_type - and d["object_parent_name"] == object_parent_name - ]: + try: + # Removed walrus operator so it can be compatible with with python versions before 3.8 + translations = [ + d + for d in self.ObjectTranslations + if d["object_name"] == object_name + and d["object_type"] == object_type + and d["object_parent_name"] == object_parent_name + ] return translations[0] - - return {"object_not_found": "Not Available"} + except Exception: + return {"object_not_found": "Not Available"} class PyCultures(PyObjects): diff --git a/pytabular/document.py b/pytabular/document.py index ccec1e4..332276d 100644 --- a/pytabular/document.py +++ b/pytabular/document.py @@ -332,17 +332,17 @@ def create_markdown_for_table(self, object: PyTable) -> str: "\\n", "" ) - partition_type = '' - partition_source = '' + partition_type = "" + partition_source = "" - if str(object.Partitions[0].SourceType) == 'Calculated': - partition_type = 'dax' + if str(object.Partitions[0].SourceType) == "Calculated": + partition_type = "dax" partition_source = object.Partitions[0].Source.Expression - elif str(object.Partitions[0].SourceType) == 'M': - partition_type = 'powerquery' + elif str(object.Partitions[0].SourceType) == "M": + partition_type = "powerquery" partition_source = object.Partitions[0].Source.Expression else: - partition_type = 'sql' + partition_type = "sql" partition_source = object.Partitions[0].Source.Query return f""" diff --git a/pytabular/logic_utils.py b/pytabular/logic_utils.py index ac5e7c2..342007c 100644 --- a/pytabular/logic_utils.py +++ b/pytabular/logic_utils.py @@ -177,7 +177,7 @@ def get_value_to_df(Query: AdomdDataReader, index: int): return Query.GetValue(index) -def dataframe_to_dict(df: pd.DataFrame) -> list[dict]: +def dataframe_to_dict(df: pd.DataFrame) -> List[dict]: """Convert to Dataframe to dictionary and alter columns names with; - Underscores (_) to spaces - All Strings are converted to Title Case. diff --git a/test/conftest.py b/test/conftest.py index 50e428b..1654d5a 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -8,6 +8,7 @@ class testing_storage: query_trace = None + documentation_class = None def pytest_report_header(config): diff --git a/test/test_11document.py b/test/test_11document.py new file mode 100644 index 0000000..8e40bf3 --- /dev/null +++ b/test/test_11document.py @@ -0,0 +1,26 @@ +"""Tests to cover the document.py file +""" +from test.config import testing_parameters +import pytest +import pytabular as p +import os +from pytabular import logic_utils +from test.conftest import testing_storage + + +@pytest.mark.parametrize("model", testing_parameters) +def test_basic_document_funcionality(model): + try: + docs = p.ModelDocumenter(model=model) + docs.generate_documentation_pages() + docs.save_documentation() + testing_storage.documentation_class = docs + except Exception: + pytest.fail("Unsuccessful documentation generation..") + + +def test_basic_documentation_removed(): + docs_class = testing_storage.documentation_class + remove = f"{docs_class.save_location}/{docs_class.friendly_name}" + logic_utils.remove_folder_and_contents(remove) + assert os.path.exists(remove) is False