Repository: codezonediitj/pydatastructs (language: python)

Issue:
Add pydatastructs.test function to run tests
#### Description of the problem
<!--Please provide a clear and details information of the bug/data structure to be added.-->
The above function would make it easier for the user to verify the installation of PyDataStructs APIs.

#### Example of the problem
<!--Provide a reproducible example code which is causing the bug to appear. Leave this section if the problem is not a bug.-->

#### References/Other comments



Discussion / hints:
I'd like to work on it
Sure. Go ahead.
Can you please assign this to me?
Hey @ShubhamNagure. We don't assign issues. You can read our issue policy, https://github.com/codezonediitj/pydatastructs/wiki/Issue-Policy

Fix patch:
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 1bd2f158b..967fd85cb 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -93,7 +93,7 @@ jobs:
 
       - name: Run tests
         run: |
-          python -m pytest --doctest-modules --cov=./ --cov-report=xml -s
+          python -c "import pydatastructs; pydatastructs.test(include_benchmarks=True)"
 
       - name: Build Documentation
         run: |
@@ -134,7 +134,7 @@ jobs:
 
       - name: Run tests
         run: |
-          python -m pytest --doctest-modules --cov=./ --cov-report=xml -s
+          python -c "import pydatastructs; pydatastructs.test()"
 
       - name: Build Documentation
         run: |
@@ -142,7 +142,7 @@ jobs:
 
   test-windows:
     runs-on: ${{matrix.os}}
-    timeout-minutes: 10
+    timeout-minutes: 15
     strategy:
       fail-fast: false
       matrix:
@@ -182,7 +182,7 @@ jobs:
 
       - name: Run tests
         run: |
-          python -m pytest --doctest-modules --cov=./ --cov-report=xml -s
+          python -c "import pydatastructs; pydatastructs.test()"
 
       - name: Build Documentation
         run: |
diff --git a/pydatastructs/graphs/__init__.py b/pydatastructs/graphs/__init__.py
index ad6006342..9c00ca0aa 100644
--- a/pydatastructs/graphs/__init__.py
+++ b/pydatastructs/graphs/__init__.py
@@ -7,6 +7,9 @@
 __all__.extend(graph.__all__)
 
 from . import algorithms
+from . import adjacency_list
+from . import adjacency_matrix
+
 from .algorithms import (
     breadth_first_search,
     breadth_first_search_parallel,
diff --git a/pydatastructs/utils/__init__.py b/pydatastructs/utils/__init__.py
index 9f2fee894..707f28791 100644
--- a/pydatastructs/utils/__init__.py
+++ b/pydatastructs/utils/__init__.py
@@ -1,6 +1,7 @@
 __all__ = []
 
 from . import misc_util
+from . import testing_util
 from .misc_util import (
     TreeNode,
     MAryTreeNode,
@@ -19,4 +20,7 @@
     minimum,
     Backend
 )
+from .testing_util import test
+
 __all__.extend(misc_util.__all__)
+__all__.extend(testing_util.__all__)


Test patch:
diff --git a/pydatastructs/utils/testing_util.py b/pydatastructs/utils/testing_util.py
new file mode 100644
index 000000000..f1bfa421f
--- /dev/null
+++ b/pydatastructs/utils/testing_util.py
@@ -0,0 +1,81 @@
+try:
+    import pytest
+except ImportError:
+    raise Exception("pytest must be installed. Use `pip install pytest` "
+                    "to install it.")
+
+import os
+import pathlib
+import glob
+import types
+
+__all__ = ['test']
+
+
+# Root pydatastructs directory
+ROOT_DIR = pathlib.Path(os.path.abspath(__file__)).parents[2]
+
+
+SKIP_FILES = ['testing_util.py']
+
+def test(submodules=None, include_benchmarks=False,
+         benchmarks_size=1000, **kwargs):
+    """
+    Runs the library tests using pytest
+
+    Parameters
+    ==========
+
+    submodules: Optional, list[str]
+        List of submodules test to run. By default runs
+        all the tests
+    """
+    # set benchmarks size
+    os.environ["PYDATASTRUCTS_BENCHMARK_SIZE"] = str(benchmarks_size)
+    test_files = []
+    if submodules:
+        if not isinstance(submodules, (list, tuple)):
+            submodules = [submodules]
+        for path in glob.glob(f'{ROOT_DIR}/**/test_*.py', recursive=True):
+            skip_test = False
+            for skip in SKIP_FILES:
+                if skip in path:
+                    skip_test = True
+                    break
+            if skip_test:
+                continue
+            for sub_var in submodules:
+                if isinstance(sub_var, types.ModuleType):
+                    sub = sub_var.__name__.split('.')[-1]
+                elif isinstance(sub_var, str):
+                    sub = sub_var
+                else:
+                    raise Exception("Submodule should be of type: str or module")
+                if sub in path:
+                    if not include_benchmarks:
+                        if not 'benchmarks' in path:
+                            test_files.append(path)
+                    else:
+                        test_files.append(path)
+                    break
+    else:
+        for path in glob.glob(f'{ROOT_DIR}/**/test_*.py', recursive=True):
+            skip_test = False
+            for skip in SKIP_FILES:
+                if skip in path:
+                    skip_test = True
+                    break
+            if skip_test:
+                continue
+            if not include_benchmarks:
+                if not 'benchmarks' in path:
+                    test_files.append(path)
+            else:
+                test_files.append(path)
+
+    extra_args = []
+    if not kwargs.get("n", False) is False:
+        extra_args.append("-n")
+        extra_args.append(str(kwargs["n"]))
+
+    pytest.main(extra_args + test_files)