Repository: sanders41/sas7bdat-converter

Issue:
Allow file paths as either a string or Path object
Update the function parameters to give the user a choice if they want to send the paths as strings or Path objects.


Discussion:

Resolving patch:
diff --git a/sas7bdat_converter/converter.py b/sas7bdat_converter/converter.py
--- a/sas7bdat_converter/converter.py
+++ b/sas7bdat_converter/converter.py
@@ -1,7 +1,6 @@
 import csv
-import json
 from pathlib import Path
-from typing import Dict, List, Optional, Tuple
+from typing import Dict, List, Optional, Tuple, Union
 from xml.sax.saxutils import escape
 
 import numpy as np
@@ -13,7 +12,7 @@
 ]
 
 
-def batch_to_csv(file_dicts: List[Dict[str, str]]) -> None:
+def batch_to_csv(file_dicts: List[Dict[str, Union[str, Path]]]) -> None:
     """
     Converts a batch of sas7bdat files to csv files.
 
@@ -27,12 +26,12 @@ def batch_to_csv(file_dicts: List[Dict[str, str]]) -> None:
     for file_dict in file_dicts:
         _rise_on_invalid_file_dict(file_dict)
 
-        sas7bdat = file_dict["sas7bdat_file"]
-        export = file_dict["export_file"]
+        sas7bdat = _format_path(file_dict["sas7bdat_file"])
+        export = _format_path(file_dict["export_file"])
         to_csv(sas7bdat_file=sas7bdat, export_file=export)
 
 
-def batch_to_excel(file_dicts: List[Dict[str, str]]) -> None:
+def batch_to_excel(file_dicts: List[Dict[str, Union[str, Path]]]) -> None:
     """
     Converts a batch of sas7bdat files to xlsx files.
 
@@ -46,12 +45,12 @@ def batch_to_excel(file_dicts: List[Dict[str, str]]) -> None:
     for file_dict in file_dicts:
         _rise_on_invalid_file_dict(file_dict)
 
-        sas7bdat = file_dict["sas7bdat_file"]
-        export = file_dict["export_file"]
+        sas7bdat = _format_path(file_dict["sas7bdat_file"])
+        export = _format_path(file_dict["export_file"])
         to_excel(sas7bdat_file=sas7bdat, export_file=export)
 
 
-def batch_to_json(file_dicts: List[Dict[str, str]]) -> None:
+def batch_to_json(file_dicts: List[Dict[str, Union[str, Path]]]) -> None:
     """
     Converts a batch of sas7bdat files to json files.
 
@@ -65,12 +64,12 @@ def batch_to_json(file_dicts: List[Dict[str, str]]) -> None:
     for file_dict in file_dicts:
         _rise_on_invalid_file_dict(file_dict)
 
-        sas7bdat = file_dict["sas7bdat_file"]
-        export = file_dict["export_file"]
+        sas7bdat = _format_path(file_dict["sas7bdat_file"])
+        export = _format_path(file_dict["export_file"])
         to_json(sas7bdat_file=sas7bdat, export_file=export)
 
 
-def batch_to_xml(file_dicts: List[Dict[str, str]]) -> None:
+def batch_to_xml(file_dicts: List[Dict[str, Union[str, Path]]]) -> None:
     """
     Converts a batch of sas7bdat files to xml files.
 
@@ -120,8 +119,8 @@ def batch_to_xml(file_dicts: List[Dict[str, str]]) -> None:
             )
             raise KeyError(message)
 
-        sas7bdat = file_dict["sas7bdat_file"]
-        export = file_dict["export_file"]
+        sas7bdat = _format_path(file_dict["sas7bdat_file"])
+        export = _format_path(file_dict["export_file"])
         root_node = None
         first_node = None
         if "root_node" in file_dict:
@@ -133,41 +132,34 @@ def batch_to_xml(file_dicts: List[Dict[str, str]]) -> None:
             to_xml(
                 sas7bdat_file=sas7bdat,
                 export_file=export,
-                root_node=root_node,
-                first_node=first_node,
+                root_node=str(root_node),
+                first_node=str(first_node),
             )
         elif root_node:
-            to_xml(sas7bdat_file=sas7bdat, export_file=export, root_node=root_node)
+            to_xml(sas7bdat_file=sas7bdat, export_file=export, root_node=str(root_node))
         elif first_node:
-            to_xml(sas7bdat_file=sas7bdat, export_file=export, first_node=first_node)
+            to_xml(sas7bdat_file=sas7bdat, export_file=export, first_node=str(first_node))
         else:
             to_xml(sas7bdat_file=sas7bdat, export_file=export)
 
 
-def dir_to_csv(dir_path: str, export_path: Optional[str] = None) -> None:
+def dir_to_csv(dir_path: Union[str, Path], export_path: Optional[Union[str, Path]] = None) -> None:
     """
     Converts all sas7bdat files in a directory into csv files.
 
     args:
-        dir_path: The pah to the directory that contains the sas7bdat files
+        dir_path: The path to the directory that contains the sas7bdat files
                 for conversion.
         export_path (optional): If used this can specify a new directory to create
                 the converted files into. If not supplied then the files will be
                 created into the same directory as dir_path.
     """
-    for file_name in Path(dir_path).iterdir():
-        if file_name.suffix == ".sas7bdat":
-            export_file = Path(f"{file_name.stem}.csv")
-            if export_path:
-                export_file = Path(export_path).joinpath(export_file)
-            else:
-                export_file = Path(dir_path).joinpath(export_file)
-
-            sas7bdat_file = Path(dir_path).joinpath(file_name)
-            to_csv(str(sas7bdat_file), str(export_file))
+    _walk_dir("csv", dir_path, export_path)
 
 
-def dir_to_excel(dir_path: str, export_path: Optional[str] = None) -> None:
+def dir_to_excel(
+    dir_path: Union[str, Path], export_path: Optional[Union[str, Path]] = None
+) -> None:
     """
     Converts all sas7bdat files in a directory into xlsx files.
 
@@ -178,19 +170,10 @@ def dir_to_excel(dir_path: str, export_path: Optional[str] = None) -> None:
                 the converted files into. If not supplied then the files will be
                 created into the same directory as dir_path.
     """
-    for file_name in Path(dir_path).iterdir():
-        if file_name.suffix == ".sas7bdat":
-            export_file = Path(f"{file_name.stem}.xlsx")
-            if export_path:
-                export_file = Path(export_path).joinpath(export_file)
-            else:
-                export_file = Path(dir_path).joinpath(export_file)
-
-            sas7bdat_file = Path(dir_path).joinpath(file_name)
-            to_excel(str(sas7bdat_file), str(export_file))
+    _walk_dir("xlsx", dir_path, export_path)
 
 
-def dir_to_json(dir_path: str, export_path: Optional[str] = None) -> None:
+def dir_to_json(dir_path: Union[str, Path], export_path: Optional[Union[str, Path]] = None) -> None:
     """
     Converts all sas7bdat files in a directory into json files.
 
@@ -201,19 +184,10 @@ def dir_to_json(dir_path: str, export_path: Optional[str] = None) -> None:
                 the converted files into. If not supplied then the files will be
                 created into the same directory as dir_path.
     """
-    for file_name in Path(dir_path).iterdir():
-        if file_name.suffix == ".sas7bdat":
-            export_file = Path(f"{file_name.stem}.json")
-            if export_path:
-                export_file = Path(export_path).joinpath(export_file)
-            else:
-                export_file = Path(dir_path).joinpath(export_file)
+    _walk_dir("json", dir_path, export_path)
 
-            sas7bdat_file = Path(dir_path).joinpath(file_name)
-            to_json(str(sas7bdat_file), str(export_file))
 
-
-def dir_to_xml(dir_path: str, export_path: Optional[str] = None) -> None:
+def dir_to_xml(dir_path: Union[str, Path], export_path: Optional[Union[str, Path]] = None) -> None:
     """
     Converts all sas7bdat files in a directory into xml files.
 
@@ -224,19 +198,10 @@ def dir_to_xml(dir_path: str, export_path: Optional[str] = None) -> None:
                 the converted files into. If not supplied then the files will be
                 created into the same directory as dir_path.
     """
-    for file_name in Path(dir_path).iterdir():
-        if file_name.suffix == ".sas7bdat":
-            export_file = Path(f"{file_name.stem}.xml")
-            if export_path:
-                export_file = Path(export_path).joinpath(export_file)
-            else:
-                export_file = Path(dir_path).joinpath(export_file)
-
-            sas7bdat_file = Path(dir_path).joinpath(file_name)
-            to_xml(str(sas7bdat_file), str(export_file))
+    _walk_dir("xml", dir_path, export_path)
 
 
-def to_csv(sas7bdat_file: str, export_file: str) -> None:
+def to_csv(sas7bdat_file: Union[str, Path], export_file: Union[str, Path]) -> None:
     """
     Converts a sas7bdat file into a csv file.
 
@@ -255,7 +220,7 @@ def to_csv(sas7bdat_file: str, export_file: str) -> None:
     df.to_csv(export_file, quoting=csv.QUOTE_NONNUMERIC, index=False)
 
 
-def to_dataframe(sas7bdat_file: str) -> pd.DataFrame:
+def to_dataframe(sas7bdat_file: Union[str, Path]) -> pd.DataFrame:
     """
     Converts a sas7bdat file into a pandas dataframe.
 
@@ -279,7 +244,7 @@ def to_dataframe(sas7bdat_file: str) -> pd.DataFrame:
     return df
 
 
-def to_excel(sas7bdat_file: str, export_file: str) -> None:
+def to_excel(sas7bdat_file: Union[str, Path], export_file: Union[str, Path]) -> None:
     """
    Converts a sas7bdat file into a xlsx file.
 
@@ -298,7 +263,7 @@ def to_excel(sas7bdat_file: str, export_file: str) -> None:
     df.to_excel(export_file, index=False)
 
 
-def to_json(sas7bdat_file: str, export_file: str) -> None:
+def to_json(sas7bdat_file: Union[str, Path], export_file: Union[str, Path]) -> None:
     """
     Converts a sas7bdat file into a json file.
 
@@ -318,7 +283,10 @@ def to_json(sas7bdat_file: str, export_file: str) -> None:
 
 
 def to_xml(
-    sas7bdat_file: str, export_file: str, root_node: str = "root", first_node: str = "item"
+    sas7bdat_file: Union[str, Path],
+    export_file: Union[str, Path],
+    root_node: str = "root",
+    first_node: str = "item",
 ) -> None:
     """
     Converts a sas7bdat file into a xml file.
@@ -383,9 +351,37 @@ def _is_valid_extension(valid_extensions: Tuple[str], file_extension: str) -> bo
     return file_extension in valid_extensions
 
 
-def _rise_on_invalid_file_dict(file_dict: Dict[str, str]) -> None:
+def _format_path(path: Union[str, Path]) -> str:
+    return str(path) if isinstance(path, Path) else path
+
+
+def _rise_on_invalid_file_dict(file_dict: Dict[str, Union[str, Path]]) -> None:
     if len(set(file_dict).intersection(__file_dict_required_keys)) != len(
         __file_dict_required_keys
     ):
         message = _invalid_key_exception_message(required_keys=__file_dict_required_keys)
         raise KeyError(message)
+
+
+def _walk_dir(
+    file_type: str, dir_path: Union[str, Path], export_path: Optional[Union[str, Path]] = None,
+) -> None:
+    path = dir_path if isinstance(dir_path, Path) else Path(dir_path)
+    for file_name in path.iterdir():
+        if file_name.suffix == ".sas7bdat":
+            export_file = Path(f"{file_name.stem}.{file_type}")
+            if export_path:
+                export_file = Path(export_path).joinpath(export_file)
+            else:
+                export_file = path.joinpath(export_file)
+
+            sas7bdat_file = path.joinpath(file_name)
+
+            if file_type == "csv":
+                to_csv(str(sas7bdat_file), str(export_file))
+            elif file_type == "xlsx":
+                to_excel(str(sas7bdat_file), str(export_file))
+            elif file_type == "json":
+                to_json(str(sas7bdat_file), str(export_file))
+            elif file_type == "xml":
+                to_xml(str(sas7bdat_file), str(export_file))


Test patch:
diff --git a/tests/test_sas7bdat_converter.py b/tests/test_sas7bdat_converter.py
--- a/tests/test_sas7bdat_converter.py
+++ b/tests/test_sas7bdat_converter.py
@@ -11,10 +11,10 @@
 current_dir = Path().absolute()
 
 
-def test_batch_to_csv(tmpdir, sas_file_1, sas_file_2, sas_file_3):
-    converted_file_1 = Path(tmpdir).joinpath("file1.csv")
-    converted_file_2 = Path(tmpdir).joinpath("file2.csv")
-    converted_file_3 = Path(tmpdir).joinpath("file3.csv")
+def test_batch_to_csv_path(tmp_path, sas_file_1, sas_file_2, sas_file_3):
+    converted_file_1 = tmp_path.joinpath("file1.csv")
+    converted_file_2 = tmp_path.joinpath("file2.csv")
+    converted_file_3 = tmp_path.joinpath("file3.csv")
 
     file_dict = [
         {"sas7bdat_file": sas_file_1, "export_file": converted_file_1},
@@ -32,6 +32,27 @@ def test_batch_to_csv(tmpdir, sas_file_1, sas_file_2, sas_file_3):
     assert files_created
 
 
+def test_batch_to_csv_str(tmp_path, sas_file_1, sas_file_2, sas_file_3):
+    converted_file_1 = tmp_path.joinpath("file1.csv")
+    converted_file_2 = tmp_path.joinpath("file2.csv")
+    converted_file_3 = tmp_path.joinpath("file3.csv")
+
+    file_dict = [
+        {"sas7bdat_file": str(sas_file_1), "export_file": str(converted_file_1)},
+        {"sas7bdat_file": str(sas_file_2), "export_file": str(converted_file_2)},
+        {"sas7bdat_file": str(sas_file_3), "export_file": str(converted_file_3)},
+    ]
+
+    converter.batch_to_csv(file_dict)
+
+    files_created = False
+
+    if converted_file_1.is_file() and converted_file_2.is_file() and converted_file_3.is_file():
+        files_created = True
+
+    assert files_created
+
+
 file_dicts = [
     [{"bad_key": "test.sas7bdat", "export_file": "test.csv"}],
     [{"sas7bdat_file": "test.sas7bdat", "bad_key": "test.csv"}],
@@ -47,10 +68,10 @@ def test_batch_to_csv_invalid_key(file_dict):
     assert "Invalid key provided" in str(execinfo.value)
 
 
-def test_batch_to_excel(tmpdir, sas_file_1, sas_file_2, sas_file_3):
-    converted_file_1 = Path(tmpdir).joinpath("file1.xlsx")
-    converted_file_2 = Path(tmpdir).joinpath("file2.xlsx")
-    converted_file_3 = Path(tmpdir).joinpath("file3.xlsx")
+def test_batch_to_excel_path(tmp_path, sas_file_1, sas_file_2, sas_file_3):
+    converted_file_1 = tmp_path.joinpath("file1.xlsx")
+    converted_file_2 = tmp_path.joinpath("file2.xlsx")
+    converted_file_3 = tmp_path.joinpath("file3.xlsx")
 
     file_dict = [
         {"sas7bdat_file": sas_file_1, "export_file": converted_file_1},
@@ -67,6 +88,26 @@ def test_batch_to_excel(tmpdir, sas_file_1, sas_file_2, sas_file_3):
     assert files_created
 
 
+def test_batch_to_excel_str(tmp_path, sas_file_1, sas_file_2, sas_file_3):
+    converted_file_1 = tmp_path.joinpath("file1.xlsx")
+    converted_file_2 = tmp_path.joinpath("file2.xlsx")
+    converted_file_3 = tmp_path.joinpath("file3.xlsx")
+
+    file_dict = [
+        {"sas7bdat_file": str(sas_file_1), "export_file": str(converted_file_1)},
+        {"sas7bdat_file": str(sas_file_2), "export_file": str(converted_file_2)},
+        {"sas7bdat_file": str(sas_file_3), "export_file": str(converted_file_3)},
+    ]
+
+    converter.batch_to_excel(file_dict)
+    files_created = False
+
+    if converted_file_1.is_file() and converted_file_2.is_file() and converted_file_3.is_file():
+        files_created = True
+
+    assert files_created
+
+
 file_dicts = [
     [{"bad_key": "test.sas7bdat", "export_file": "test.xlsx"}],
     [{"sas7bdat_file": "test.sas7bdat", "bad_key": "test.xlsx"}],
@@ -82,10 +123,10 @@ def test_batch_to_excel_invalid_key(file_dict):
     assert "Invalid key provided" in str(execinfo.value)
 
 
-def test_batch_to_json(tmpdir, sas_file_1, sas_file_2, sas_file_3):
-    converted_file_1 = Path(tmpdir).joinpath("file1.json")
-    converted_file_2 = Path(tmpdir).joinpath("file2.json")
-    converted_file_3 = Path(tmpdir).joinpath("file3.json")
+def test_batch_to_json_path(tmp_path, sas_file_1, sas_file_2, sas_file_3):
+    converted_file_1 = tmp_path.joinpath("file1.json")
+    converted_file_2 = tmp_path.joinpath("file2.json")
+    converted_file_3 = tmp_path.joinpath("file3.json")
 
     file_dict = [
         {"sas7bdat_file": sas_file_1, "export_file": converted_file_1},
@@ -102,6 +143,26 @@ def test_batch_to_json(tmpdir, sas_file_1, sas_file_2, sas_file_3):
     assert files_created
 
 
+def test_batch_to_json_path_str(tmp_path, sas_file_1, sas_file_2, sas_file_3):
+    converted_file_1 = tmp_path.joinpath("file1.json")
+    converted_file_2 = tmp_path.joinpath("file2.json")
+    converted_file_3 = tmp_path.joinpath("file3.json")
+
+    file_dict = [
+        {"sas7bdat_file": str(sas_file_1), "export_file": str(converted_file_1)},
+        {"sas7bdat_file": str(sas_file_2), "export_file": str(converted_file_2)},
+        {"sas7bdat_file": str(sas_file_3), "export_file": str(converted_file_3)},
+    ]
+
+    converter.batch_to_json(file_dict)
+    files_created = False
+
+    if converted_file_1.is_file() and converted_file_2.is_file() and converted_file_3.is_file():
+        files_created = True
+
+    assert files_created
+
+
 file_dicts = [
     [{"bad_key": "test.sas7bdat", "export_file": "test.json"}],
     [{"sas7bdat_file": "test.sas7bdat", "bad_key": "test.json"}],
@@ -126,10 +187,10 @@ def test_batch_to_json_invalid_key(file_dict):
 
 
 @pytest.mark.parametrize("optional", optionals)
-def test_batch_to_xml(tmpdir, sas_file_1, sas_file_2, sas_file_3, optional):
-    converted_file_1 = Path(tmpdir).joinpath("file1.xml")
-    converted_file_2 = Path(tmpdir).joinpath("file2.xml")
-    converted_file_3 = Path(tmpdir).joinpath("file3.xml")
+def test_batch_to_xml_path(tmp_path, sas_file_1, sas_file_2, sas_file_3, optional):
+    converted_file_1 = tmp_path.joinpath("file1.xml")
+    converted_file_2 = tmp_path.joinpath("file2.xml")
+    converted_file_3 = tmp_path.joinpath("file3.xml")
 
     if optional.get("root_node") and optional.get("first_node"):
         file_dict = [
@@ -204,6 +265,85 @@ def test_batch_to_xml(tmpdir, sas_file_1, sas_file_2, sas_file_3, optional):
     assert files_created
 
 
+@pytest.mark.parametrize("optional", optionals)
+def test_batch_to_xml_str(tmp_path, sas_file_1, sas_file_2, sas_file_3, optional):
+    converted_file_1 = tmp_path.joinpath("file1.xml")
+    converted_file_2 = tmp_path.joinpath("file2.xml")
+    converted_file_3 = tmp_path.joinpath("file3.xml")
+
+    if optional.get("root_node") and optional.get("first_node"):
+        file_dict = [
+            {
+                "sas7bdat_file": str(sas_file_1),
+                "export_file": str(converted_file_1),
+                "root_node": optional.get("root_node"),
+                "first_node": optional.get("first_node"),
+            },
+            {
+                "sas7bdat_file": str(sas_file_2),
+                "export_file": str(converted_file_2),
+                "root_node": optional.get("root_node"),
+                "first_node": optional.get("first_node"),
+            },
+            {
+                "sas7bdat_file": str(sas_file_3),
+                "export_file": str(converted_file_3),
+                "root_node": optional.get("root_node"),
+                "first_node": optional.get("first_node"),
+            },
+        ]
+    elif optional.get("root_node"):
+        file_dict = [
+            {
+                "sas7bdat_file": str(sas_file_1),
+                "export_file": str(converted_file_1),
+                "root_node": optional.get("root_node"),
+            },
+            {
+                "sas7bdat_file": str(sas_file_2),
+                "export_file": str(converted_file_2),
+                "root_node": optional.get("root_node"),
+            },
+            {
+                "sas7bdat_file": str(sas_file_3),
+                "export_file": str(converted_file_3),
+                "root_node": optional.get("root_node"),
+            },
+        ]
+    elif optional.get("first_node"):
+        file_dict = [
+            {
+                "sas7bdat_file": str(sas_file_1),
+                "export_file": str(converted_file_1),
+                "first_node": optional.get("first_node"),
+            },
+            {
+                "sas7bdat_file": str(sas_file_2),
+                "export_file": str(converted_file_2),
+                "first_node": optional.get("first_node"),
+            },
+            {
+                "sas7bdat_file": str(sas_file_3),
+                "export_file": str(converted_file_3),
+                "first_node": optional.get("first_node"),
+            },
+        ]
+    else:
+        file_dict = [
+            {"sas7bdat_file": str(sas_file_1), "export_file": str(converted_file_1),},
+            {"sas7bdat_file": str(sas_file_2), "export_file": str(converted_file_2),},
+            {"sas7bdat_file": str(sas_file_3), "export_file": str(converted_file_3),},
+        ]
+
+    converter.batch_to_xml(file_dict)
+    files_created = False
+
+    if converted_file_1.is_file() and converted_file_2.is_file() and converted_file_3.is_file():
+        files_created = True
+
+    assert files_created
+
+
 file_dicts = [
     [{"bad_key": "test.sas7bdat", "export_file": "test.xml"}],
     [{"sas7bdat_file": "test.sas7bdat", "bad_key": "test.xml"}],
@@ -235,82 +375,162 @@ def test_batch_to_xml_invalid_key(file_dict):
     assert "Invalid key provided" in str(execinfo.value)
 
 
-def test_dir_to_csv_same_dir(tmpdir, sas7bdat_dir):
+def test_dir_to_csv_same_dir_path(tmp_path, sas7bdat_dir):
+    sas_files = [str(x) for x in sas7bdat_dir.iterdir()]
+    for sas_file in sas_files:
+        shutil.copy(sas_file, str(tmp_path))
+
+    converter.dir_to_csv(tmp_path)
+    sas_counter = len([name for name in tmp_path.iterdir() if name.suffix == ".sas7bdat"])
+    convert_counter = len([name for name in tmp_path.iterdir() if name.suffix == ".csv"])
+
+    assert sas_counter == convert_counter
+
+
+def test_dir_to_csv_same_dir_str(tmpdir, sas7bdat_dir):
     sas_files = [str(x) for x in sas7bdat_dir.iterdir()]
     for sas_file in sas_files:
         shutil.copy(sas_file, tmpdir)
 
-    converter.dir_to_csv(str(tmpdir))
-    sas_counter = len([name for name in Path(tmpdir).iterdir() if name.suffix == "sas7bdat"])
-    convert_counter = len([name for name in Path(tmpdir).iterdir() if name.suffix == "csv"])
+    converter.dir_to_csv(tmpdir)
+    sas_counter = len([name for name in Path(tmpdir).iterdir() if name.suffix == ".sas7bdat"])
+    convert_counter = len([name for name in Path(tmpdir).iterdir() if name.suffix == ".csv"])
+
+    assert sas_counter == convert_counter
+
+
+def test_dir_to_csv_different_dir_path(tmp_path, sas7bdat_dir):
+    converter.dir_to_csv(dir_path=sas7bdat_dir, export_path=tmp_path)
+    sas_counter = len([name for name in sas7bdat_dir.iterdir() if name.suffix == ".sas7bdat"])
+    convert_counter = len([name for name in tmp_path.iterdir() if name.suffix == ".csv"])
 
     assert sas_counter == convert_counter
 
 
-def test_dir_to_csv_different_dir(tmpdir, sas7bdat_dir):
-    converter.dir_to_csv(dir_path=str(sas7bdat_dir), export_path=str(tmpdir))
-    sas_counter = len([name for name in Path(sas7bdat_dir).iterdir() if name.suffix == "sas7bdat"])
-    convert_counter = len([name for name in Path(tmpdir).iterdir() if name.suffix == "csv"])
+def test_dir_to_csv_different_dir_str(tmpdir, sas7bdat_dir):
+    converter.dir_to_csv(dir_path=str(sas7bdat_dir), export_path=tmpdir)
+    sas_counter = len([name for name in Path(sas7bdat_dir).iterdir() if name.suffix == ".sas7bdat"])
+    convert_counter = len([name for name in Path(tmpdir).iterdir() if name.suffix == ".csv"])
+
+    assert sas_counter == convert_counter
+
+
+def test_dir_to_excel_same_dir_path(tmp_path, sas7bdat_dir):
+    sas_files = [x for x in sas7bdat_dir.iterdir()]
+    for sas_file in sas_files:
+        shutil.copy(sas_file, str(tmp_path))
+
+    converter.dir_to_excel(tmp_path)
+    sas_counter = len([name for name in tmp_path.iterdir() if name.suffix == ".sas7bdat"])
+    convert_counter = len([name for name in tmp_path.iterdir() if name.suffix == ".xlsx"])
 
     assert sas_counter == convert_counter
 
 
-def test_dir_to_excel_same_dir(tmpdir, sas7bdat_dir):
+def test_dir_to_excel_same_dir_str(tmpdir, sas7bdat_dir):
     sas_files = [str(x) for x in sas7bdat_dir.iterdir()]
     for sas_file in sas_files:
         shutil.copy(sas_file, tmpdir)
 
-    converter.dir_to_excel(str(tmpdir))
-    sas_counter = len([name for name in Path(tmpdir).iterdir() if name.suffix == "sas7bdat"])
-    convert_counter = len([name for name in Path(tmpdir).iterdir() if name.suffix == "xlsx"])
+    converter.dir_to_excel(tmpdir)
+    sas_counter = len([name for name in Path(tmpdir).iterdir() if name.suffix == ".sas7bdat"])
+    convert_counter = len([name for name in Path(tmpdir).iterdir() if name.suffix == ".xlsx"])
 
     assert sas_counter == convert_counter
 
 
-def test_dir_to_excel_different_dir(tmpdir, sas7bdat_dir):
-    converter.dir_to_excel(dir_path=str(sas7bdat_dir), export_path=str(tmpdir))
-    sas_counter = len([name for name in Path(sas7bdat_dir).iterdir() if name.suffix == "sas7bdat"])
-    convert_counter = len([name for name in Path(tmpdir).iterdir() if name.suffix == "xlsx"])
+def test_dir_to_excel_different_dir_path(tmp_path, sas7bdat_dir):
+    converter.dir_to_excel(dir_path=sas7bdat_dir, export_path=tmp_path)
+    sas_counter = len([name for name in sas7bdat_dir.iterdir() if name.suffix == ".sas7bdat"])
+    convert_counter = len([name for name in tmp_path.iterdir() if name.suffix == ".xlsx"])
 
     assert sas_counter == convert_counter
 
 
-def test_dir_to_json_same_dir(tmpdir, sas7bdat_dir):
+def test_dir_to_excel_different_dir_str(tmpdir, sas7bdat_dir):
+    converter.dir_to_excel(dir_path=str(sas7bdat_dir), export_path=tmpdir)
+    sas_counter = len([name for name in Path(sas7bdat_dir).iterdir() if name.suffix == ".sas7bdat"])
+    convert_counter = len([name for name in Path(tmpdir).iterdir() if name.suffix == ".xlsx"])
+
+    assert sas_counter == convert_counter
+
+
+def test_dir_to_json_same_dir_path(tmp_path, sas7bdat_dir):
+    sas_files = [x for x in sas7bdat_dir.iterdir()]
+    for sas_file in sas_files:
+        shutil.copy(sas_file, tmp_path)
+
+    converter.dir_to_json(tmp_path)
+    sas_counter = len([name for name in tmp_path.iterdir() if name.suffix == ".sas7bdat"])
+    convert_counter = len([name for name in tmp_path.iterdir() if name.suffix == ".json"])
+
+    assert sas_counter == convert_counter
+
+
+def test_dir_to_json_same_dir_str(tmpdir, sas7bdat_dir):
     sas_files = [str(x) for x in sas7bdat_dir.iterdir()]
     for sas_file in sas_files:
         shutil.copy(sas_file, tmpdir)
 
-    converter.dir_to_json(str(tmpdir))
-    sas_counter = len([name for name in Path(tmpdir).iterdir() if name.suffix == "sas7bdat"])
-    convert_counter = len([name for name in Path(tmpdir).iterdir() if name.suffix == "json"])
+    converter.dir_to_json(tmpdir)
+    sas_counter = len([name for name in Path(tmpdir).iterdir() if name.suffix == ".sas7bdat"])
+    convert_counter = len([name for name in Path(tmpdir).iterdir() if name.suffix == ".json"])
+
+    assert sas_counter == convert_counter
+
+
+def test_dir_to_json_different_dir_path(tmp_path, sas7bdat_dir):
+    converter.dir_to_json(sas7bdat_dir, tmp_path)
+    sas_counter = len([name for name in sas7bdat_dir.iterdir() if name.suffix == ".sas7bdat"])
+    convert_counter = len([name for name in tmp_path.iterdir() if name.suffix == ".json"])
 
     assert sas_counter == convert_counter
 
 
-def test_dir_to_json_different_dir(tmpdir, sas7bdat_dir):
-    converter.dir_to_json(str(sas7bdat_dir), str(tmpdir))
-    sas_counter = len([name for name in Path(sas7bdat_dir).iterdir() if name.suffix == "sas7bdat"])
-    convert_counter = len([name for name in Path(tmpdir).iterdir() if name.suffix == "json"])
+def test_dir_to_json_different_dir_str(tmpdir, sas7bdat_dir):
+    converter.dir_to_json(str(sas7bdat_dir), tmpdir)
+    sas_counter = len([name for name in Path(sas7bdat_dir).iterdir() if name.suffix == ".sas7bdat"])
+    convert_counter = len([name for name in Path(tmpdir).iterdir() if name.suffix == ".json"])
 
     assert sas_counter == convert_counter
 
 
-def test_dir_to_xml_same_dir(tmpdir, sas7bdat_dir):
+def test_dir_to_xml_same_dir_path(tmp_path, sas7bdat_dir):
+    sas_files = [x for x in sas7bdat_dir.iterdir()]
+    for sas_file in sas_files:
+        shutil.copy(sas_file, str(tmp_path))
+
+    converter.dir_to_xml(tmp_path)
+    sas_counter = len([name for name in tmp_path.iterdir() if name.suffix == ".sas7bdat"])
+    convert_counter = len([name for name in tmp_path.iterdir() if name.suffix == ".xml"])
+
+    assert sas_counter == convert_counter
+
+
+def test_dir_to_xml_same_dir_str(tmpdir, sas7bdat_dir):
     sas_files = [str(x) for x in sas7bdat_dir.iterdir()]
     for sas_file in sas_files:
         shutil.copy(sas_file, tmpdir)
 
-    converter.dir_to_xml(str(tmpdir))
-    sas_counter = len([name for name in Path(tmpdir).iterdir() if name.suffix == "sas7bdat"])
-    convert_counter = len([name for name in Path(tmpdir).iterdir() if name.suffix == "xml"])
+    converter.dir_to_xml(tmpdir)
+    sas_counter = len([name for name in Path(tmpdir).iterdir() if name.suffix == ".sas7bdat"])
+    convert_counter = len([name for name in Path(tmpdir).iterdir() if name.suffix == ".xml"])
+
+    assert sas_counter == convert_counter
+
+
+def test_dir_to_xml_different_dir_path(tmp_path, sas7bdat_dir):
+    converter.dir_to_xml(sas7bdat_dir, tmp_path)
+    sas_counter = len([name for name in sas7bdat_dir.iterdir() if name.suffix == ".sas7bdat"])
+    convert_counter = len([name for name in tmp_path.iterdir() if name.suffix == ".xml"])
 
     assert sas_counter == convert_counter
 
 
-def test_dir_to_xml_different_dir(tmpdir, sas7bdat_dir):
-    converter.dir_to_xml(str(sas7bdat_dir), str(tmpdir))
-    sas_counter = len([name for name in Path(sas7bdat_dir).iterdir() if name.suffix == "sas7bdat"])
-    convert_counter = len([name for name in Path(tmpdir).iterdir() if name.suffix == "xml"])
+def test_dir_to_xml_different_dir_str(tmpdir, sas7bdat_dir):
+    converter.dir_to_xml(str(sas7bdat_dir), tmpdir)
+    sas_counter = len([name for name in Path(sas7bdat_dir).iterdir() if name.suffix == ".sas7bdat"])
+    convert_counter = len([name for name in Path(tmpdir).iterdir() if name.suffix == ".xml"])
 
     assert sas_counter == convert_counter
 
@@ -372,9 +592,19 @@ def test_is_valid_extension_true(data):
 
 
 @pytest.fixture(params=["sas_file_1", "sas_file_2", "sas_file_3"])
-def test_to_csv(tmpdir, request, expected_dir):
+def test_to_csv_path(tmp_path, request, expected_dir):
+    sas_file = Path(request.getfixturevalue(request.param))
+    converted_file = tmp_path.joinpath("file1.csv")
+    expected_file = expected_dir.joinpath("file1.csv")
+    converter.to_csv(sas_file, converted_file)
+
+    assert filecmp.cmp(converted_file, expected_file, shallow=False)
+
+
+@pytest.fixture(params=["sas_file_1", "sas_file_2", "sas_file_3"])
+def test_to_csv_str(tmpdir, request, expected_dir):
     sas_file = request.getfixturevalue(request.param)
-    converted_file = Path(tmpdir).joinpath("file1.csv")
+    converted_file = str(Path(tmpdir).joinpath("file1.csv"))
     expected_file = expected_dir.joinpath("file1.csv")
     converter.to_csv(sas_file, converted_file)
 
@@ -410,9 +640,22 @@ def test_to_dataframe(sas_file_1):
 
 
 @pytest.fixture(params=["sas_file_1", "sas_file_2", "sas_file_3"])
-def test_to_excel(tmpdir, request, expected_dir):
+def test_to_excel_path(tmp_path, request, expected_dir):
+    sas_file = Path(request.getfixturevalue(request.param))
+    converted_file = tmp_path.joinpath("file1.xlsx")
+    expected_file = expected_dir.joinpath("file1.xlsx")
+    converter.to_excel(sas_file, converted_file)
+
+    df_expected = pd.read_excel(expected_file, engine="openpyxl")
+    df_converted = pd.read_excel(converted_file, engine="openpyxl")
+
+    pd.testing.assert_frame_equal(df_expected, df_converted)
+
+
+@pytest.fixture(params=["sas_file_1", "sas_file_2", "sas_file_3"])
+def test_to_excel_str(tmpdir, request, expected_dir):
     sas_file = request.getfixturevalue(request.param)
-    converted_file = Path(tmpdir).joinpath("file1.xlsx")
+    converted_file = str(Path(tmpdir).joinpath("file1.xlsx"))
     expected_file = expected_dir.joinpath("file1.xlsx")
     converter.to_excel(sas_file, converted_file)
 
@@ -430,9 +673,19 @@ def test_to_excel_invalid_extension():
 
 
 @pytest.fixture(params=["sas_file_1", "sas_file_2", "sas_file_3"])
-def test_to_json(tmpdir, request, expected_dir):
+def test_to_json_path(tmp_path, request, expected_dir):
+    sas_file = Path(request.getfixturevalue(request.param))
+    converted_file = tmp_path.joinpath("file1.json")
+    expected_file = expected_dir.joinpath("file1.json")
+    converter.to_json(sas_file, converted_file)
+
+    assert filecmp.cmp(converted_file, expected_file, shallow=False)
+
+
+@pytest.fixture(params=["sas_file_1", "sas_file_2", "sas_file_3"])
+def test_to_json_str(tmpdir, request, expected_dir):
     sas_file = request.getfixturevalue(request.param)
-    converted_file = Path(tmpdir).joinpath("file1.json")
+    converted_file = str(Path(tmpdir).joinpath("file1.json"))
     expected_file = expected_dir.joinpath("file1.json")
     converter.to_json(sas_file, converted_file)
 
@@ -447,9 +700,19 @@ def test_to_json_invalid_extension():
 
 
 @pytest.fixture(params=["sas_file_1", "sas_file_2", "sas_file_3"])
-def test_to_xml(tmpdir, request, expected_dir):
+def test_to_xml_path(tmp_path, request, expected_dir):
+    sas_file = Path(request.getfixturevalue(request.param))
+    converted_file = tmp_path.joinpath("file1.xml")
+    expected_file = expected_dir.joinpath("file1.xml")
+    converter.to_xml(sas_file, converted_file)
+
+    assert filecmp.cmp(converted_file, expected_file, shallow=False)
+
+
+@pytest.fixture(params=["sas_file_1", "sas_file_2", "sas_file_3"])
+def test_to_xml_str(tmpdir, request, expected_dir):
     sas_file = request.getfixturevalue(request.param)
-    converted_file = Path(tmpdir).joinpath("file1.xml")
+    converted_file = str(Path(tmpdir).joinpath("file1.xml"))
     expected_file = expected_dir.joinpath("file1.xml")
     converter.to_xml(sas_file, converted_file)
 
@@ -488,3 +751,25 @@ def test_raise_on_invalid_file_dict_error(file_dict):
         converter._rise_on_invalid_file_dict(file_dict)
 
     assert "Invalid key" in str(execinfo.value)
+
+
+@pytest.mark.parametrize("path", [Path("test/path"), "test/path"])
+def test_format_path(path):
+    converted = converter._format_path(path)
+    assert converted == "test/path"
+    assert isinstance(converted, str)
+
+
+@pytest.mark.parametrize("file_type", ["csv", "xlsx", "json", "xml"])
+def test_walk_dir(tmpdir, sas7bdat_dir, file_type):
+    sas_files = [str(x) for x in sas7bdat_dir.iterdir()]
+    for sas_file in sas_files:
+        shutil.copy(sas_file, tmpdir)
+
+    converter._walk_dir(file_type, tmpdir)
+    sas_counter = len([name for name in Path(tmpdir).iterdir() if name.suffix == ".sas7bdat"])
+    convert_counter = len(
+        [name for name in Path(tmpdir).iterdir() if name.suffix == f".{file_type}"]
+    )
+
+    assert sas_counter == convert_counter