Repository: engineerjoe440/pycev (language: python)

Issue:
Improve Automated Functional Tests to Fully Validate Parsing Mechanisms
There's a number of tests that are in place which could be further elaborated upon, and these systems could be further broken out.

* Move tests into this repo
  * the CEV files should be centralized to another location where they can be accessed securely using StanleySolutions Jenkins
  * tests can be more publicly documented to help highlight what is (and is not) being covered
* Separate test files into "raw-text" and "CEV" files for more accurate test validation
* Don't let tests fail quietly (right now they are since there's some false positives)
* Add unit-tests for some of the smaller functionality


Discussion / hints:

Fix patch:
diff --git a/.github/workflows/sphinx-build.yml b/.github/workflows/sphinx-build.yml
index 463c869..34e3790 100644
--- a/.github/workflows/sphinx-build.yml
+++ b/.github/workflows/sphinx-build.yml
@@ -22,13 +22,13 @@ jobs:
       - name: Install dependencies
         run: |
           #pip install -r requirements.txt
-          pip install -r source/sphinxrequires.txt
+          pip install -r docsource/sphinxrequires.txt
       - name: Build Sphinx docs
         if: success()
         run: |
           pip install .
           python3 -c "import pycev; print('pycev.__file__')"
-          sphinx-build -M html source docs
+          sphinx-build -M html docsource docs
 
       # https://github.com/marketplace/actions/github-pages
       #- if: success()
diff --git a/README.md b/README.md
index 4aae1a1..25d0430 100644
--- a/README.md
+++ b/README.md
@@ -7,10 +7,16 @@
 [![License](https://img.shields.io/pypi/l/pycev.svg?color=blue)](https://github.com/engineerjoe440/pycev/blob/master/LICENSE.txt)
 
 
-[![Build Status](http://jenkins.stanleysolutionsnw.com/buildStatus/icon?job=PyCEV-CI)](http://jenkins.stanleysolutionsnw.com/job/PyCEV-CI/)
+[![pytest-unit-tests](https://github.com/engineerjoe440/pycev/actions/workflows/pytest-unit-tests.yml/badge.svg)](https://github.com/engineerjoe440/pycev/actions/workflows/pytest-unit-tests.yml)
 [![pydocstyle](https://github.com/engineerjoe440/pycev/actions/workflows/pydocstyle.yml/badge.svg)](https://github.com/engineerjoe440/pycev/actions/workflows/pydocstyle.yml)
 [![pylint](https://github.com/engineerjoe440/pycev/actions/workflows/pylint.yml/badge.svg)](https://github.com/engineerjoe440/pycev/actions/workflows/pylint.yml)
 
+##### Test Status
+| **Branch** | **Status** |
+|------------|------------|
+| main       | [![Build Status](https://jenkins.stanleysolutionsnw.com/buildStatus/icon?job=PyCEV-Functional-Test%2Fmain)](https://jenkins.stanleysolutionsnw.com/job/PyCEV-Functional-Test/job/main/) |
+| develop    | [![Build Status](https://jenkins.stanleysolutionsnw.com/buildStatus/icon?job=PyCEV-Functional-Test%2Fdevelop)](https://jenkins.stanleysolutionsnw.com/job/PyCEV-Functional-Test/job/develop/) |
+
 ***NOTE:*** This project is in VERY early stages of development and is nowhere near completion.
 
 ## Description:
diff --git a/ci/Jenkinsfile b/ci/Jenkinsfile
new file mode 100644
index 0000000..b01436d
--- /dev/null
+++ b/ci/Jenkinsfile
@@ -0,0 +1,27 @@
+/*******************************************************************************
+ * Stanley Solutions Jenkinsfile for PyCEV
+ *
+ * Test Execution Script for PyCEV using StanleySolutions Jenkins Systems.
+ ******************************************************************************/
+
+node('x86-64-build') {
+    stage('Test in Virtual Env') {
+
+        // Checkout Source
+        checkout scm
+
+        // With 
+        withCredentials([
+            string(credentialsId: 'pycev-files-secret',
+            variable: 'CLONE_ACCESS_URL')
+        ]) {
+
+            // Checkout CEV Resources
+            sh "git clone ${CLONE_ACCESS_URL}"
+
+        }
+
+        // Run Test Script
+        sh "/usr/bin/bash ${WORKSPACE}/ci/test.sh"
+    }
+}
\ No newline at end of file
diff --git a/source/_templates/base.rst b/docsource/_templates/base.rst
similarity index 100%
rename from source/_templates/base.rst
rename to docsource/_templates/base.rst
diff --git a/source/_templates/class.rst b/docsource/_templates/class.rst
similarity index 100%
rename from source/_templates/class.rst
rename to docsource/_templates/class.rst
diff --git a/source/_templates/module.rst b/docsource/_templates/module.rst
similarity index 100%
rename from source/_templates/module.rst
rename to docsource/_templates/module.rst
diff --git a/source/changelog.rst b/docsource/changelog.rst
similarity index 100%
rename from source/changelog.rst
rename to docsource/changelog.rst
diff --git a/source/conf.py b/docsource/conf.py
similarity index 100%
rename from source/conf.py
rename to docsource/conf.py
diff --git a/source/index.rst b/docsource/index.rst
similarity index 100%
rename from source/index.rst
rename to docsource/index.rst
diff --git a/source/pycev.rst b/docsource/pycev.rst
similarity index 100%
rename from source/pycev.rst
rename to docsource/pycev.rst
diff --git a/source/sphinxrequires.txt b/docsource/sphinxrequires.txt
similarity index 100%
rename from source/sphinxrequires.txt
rename to docsource/sphinxrequires.txt
diff --git a/pycev/pycev.py b/pycev/pycev.py
index 44153fe..8907b30 100644
--- a/pycev/pycev.py
+++ b/pycev/pycev.py
@@ -47,7 +47,7 @@
 
 # Describe Package for External Interpretation
 _name_ = "pycev"
-_version_ = "0.0"
+_version_ = "0.1.0"
 __version__ = _version_  # Alias the Version String
 
 


Test patch:
diff --git a/.github/workflows/pytest-unit-tests.yml b/.github/workflows/pytest-unit-tests.yml
new file mode 100644
index 0000000..685f730
--- /dev/null
+++ b/.github/workflows/pytest-unit-tests.yml
@@ -0,0 +1,34 @@
+name: pytest-unit-tests
+
+on:
+  push:
+    path:
+    - '**.py'
+  pull_request:
+    path:
+    - '**.py'
+
+jobs:
+  build:
+
+    runs-on: ubuntu-latest
+    strategy:
+      matrix:
+        python-version: ["3.8", "3.9", "3.10"]
+
+    steps:
+    - uses: actions/checkout@v2
+    - name: Set up Python ${{ matrix.python-version }}
+      uses: actions/setup-python@v2
+      with:
+        python-version: ${{ matrix.python-version }}
+    - name: Install dependencies
+      run: |
+        python -m pip install --upgrade pip
+        if [ -f tests/test-requires.txt ]; then pip install -r tests/test-requires.txt; fi
+        pip install .
+        python3 -c "import pycev; print('pycev.__file__')"
+    - name: Test with pytest
+      # only run the unit tests!
+      run: |
+        pytest tests/unit
\ No newline at end of file
diff --git a/ci/test.sh b/ci/test.sh
new file mode 100644
index 0000000..b63b38f
--- /dev/null
+++ b/ci/test.sh
@@ -0,0 +1,19 @@
+#!/usr/bin/bash
+
+venvDir="pycev-pytest"
+requirementsFile="tests/test-requires.txt"
+
+# Activate Environment
+python3 -m venv $venvDir
+source $WORKSPACE/$venvDir/bin/activate
+
+# Install Requirements
+python3 -m pip install -r $requirementsFile
+
+python3 -m pip install .
+
+# Run Tests
+python3 -m pytest --xdoctest
+
+# Deactivate Environment
+deactivate
\ No newline at end of file
diff --git a/tests/functional/test_loadcev.py b/tests/functional/test_loadcev.py
new file mode 100644
index 0000000..b97b11b
--- /dev/null
+++ b/tests/functional/test_loadcev.py
@@ -0,0 +1,39 @@
+################################################################################
+"""PyCEV Tests - Load a Trusted CEV and Verify Nothing Explodes."""
+################################################################################
+# pylint: disable=wrong-import-position, import-error
+
+import os
+import sys
+from pathlib import Path
+
+sys.path.insert(0, str(Path(__file__).parent.parent))
+
+# Load the pycev Package
+import pycev
+
+# Define the Path to CEV Files, and Load the Data from One Such File
+cev_dir = os.path.join( os.getcwd(), 'test', 'cev-files' )
+sel_351s_event = os.path.join( cev_dir, 'trusted-event-file.CEV' )
+with open(sel_351s_event, encoding="utf-8") as f:
+    relay_data = f.read()
+
+def test_load_using_filepath_durring_init():
+    """Parse in Constructor using File Path."""
+    pycev.CEV(file=sel_351s_event)
+
+def test_load_as_data_durring_init():
+    """Parse in Constructor using Data from File."""
+    pycev.CEV(data=relay_data)
+
+def test_load_using_filepath():
+    """Parse using Load with File Path."""
+    cev_parser = pycev.Cev()
+    cev_parser.load(file=sel_351s_event)
+
+def test_load_as_data():
+    """Parse using Load with Data from File."""
+    cev_parser = pycev.Cev()
+    cev_parser.load_data(data=relay_data)
+
+# END
diff --git a/tests/functional/test_loadeverycev.py b/tests/functional/test_loadeverycev.py
new file mode 100644
index 0000000..13f001d
--- /dev/null
+++ b/tests/functional/test_loadeverycev.py
@@ -0,0 +1,29 @@
+################################################################################
+"""PyCEV Tests - Evaluate All CEV Files."""
+################################################################################
+# pylint: disable=wrong-import-position, import-error
+
+import os
+import sys
+from pathlib import Path
+import pytest
+
+sys.path.insert(0, str(Path(__file__).parent.parent))
+
+# Load the pycev Package
+import pycev
+
+# Define the Path to CEV Files, and Load the Data from One Such File
+cev_dir = os.path.join(os.getcwd(), 'test', 'cev-files')
+cev_file_list = [f for f in os.listdir(cev_dir) if os.path.isfile(f)]
+
+# Test Each Available CEV file. The expectation is that many will fail due to
+# invalid formatting (which we'll work on later)
+@pytest.mark.xfail()
+@pytest.mark.parametrize('cev_file', cev_file_list, ids=cev_file_list)
+def test_load_every_cev_file(cev_file):
+    """Load Every File."""
+    if cev_file.upper().endswith('.CEV'):
+        pycev.CEV(file=os.path.join(cev_dir, cev_file))
+
+# END
diff --git a/tests/test-requires.txt b/tests/test-requires.txt
new file mode 100644
index 0000000..db598c2
--- /dev/null
+++ b/tests/test-requires.txt
@@ -0,0 +1,2 @@
+pytest
+xdoctest
diff --git a/tests/unit/test_importpycev.py b/tests/unit/test_importpycev.py
new file mode 100644
index 0000000..fe3e60c
--- /dev/null
+++ b/tests/unit/test_importpycev.py
@@ -0,0 +1,27 @@
+################################################################################
+"""PyCEV Tests - Import PyCEV Just to Verify No Major Issues."""
+################################################################################
+# pylint: disable=unused-import, import-error, import-outside-toplevel
+
+import sys
+from pathlib import Path
+
+sys.path.insert(0, str(Path(__file__).parent.parent))
+
+def test_import_by_name():
+    """Import Package Directly."""
+    import pycev
+
+def test_import_as_package_module():
+    """Import Module from Package."""
+    from pycev import pycev
+
+def test_import_primary_class_pascal_case():
+    """Import Class from Module - Lowercase."""
+    from pycev import Cev
+
+def test_import_primary_class_uppercase():
+    """Import Class from Module - Uppercase."""
+    from pycev import CEV
+
+# END