Skip to content

Commit

Permalink
Added an Python example project and unit tests for pytest.
Browse files Browse the repository at this point in the history
  • Loading branch information
Paebbels authored May 13, 2024
2 parents 342bf6e + b642f99 commit fa66901
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 4 deletions.
32 changes: 28 additions & 4 deletions .github/workflows/Pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,49 @@ jobs:
Java-Ant-JUnit4:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up JDK 11 for x64
- name: Set up JDK 11 for x64
uses: actions/setup-java@v4
with:
java-version: '11'
distribution: 'temurin'
architecture: x64
- name: Run the Ant 'junit' target
- name: Run the Ant 'junit' target
run: |
cd examples/Java/JUnit
ant -noinput -buildfile build-github.xml junit
- name: List generated XML reports
run: ls -lAh examples/Java/JUnit/build/*.xml
- name: Upload JUnit XML files as artifact
- name: 📤 Upload JUnit XML files as artifact
uses: actions/upload-artifact@v4
with:
name: Java-Ant-JUnit4
path: examples/Java/JUnit/build/*.xml

Python-pytest:
runs-on: ubuntu-latest
steps:
- name: ⏬ Checkout repository
uses: actions/checkout@v4
- name: 🐍 Setup Python 3.12
uses: actions/setup-python@v5
with:
python-version: 3.12
- name: 🔧 Install pytest and other dependencies
run: python -m pip install --disable-pip-version-check -U pytest
- name: ✅ Run pytest
run: |
cd examples/Python/pytest
python3 -m pytest -rAP --color=yes --junitxml=TestReportSummary.xml .
- name: List generated XML reports
run: ls -lAh examples/Python/pytest/*.xml
- name: 📤 Upload JUnit XML files as artifact
uses: actions/upload-artifact@v4
with:
name: Python-pytest
path: examples/Python/pytest/*.xml

UnitTestingParams:
uses: pyTooling/Actions/.github/workflows/Parameters.yml@r1
with:
Expand Down Expand Up @@ -83,6 +106,7 @@ jobs:
needs:
- Package
- Java-Ant-JUnit4
- Python-pytest
runs-on: ubuntu-latest
steps:
- name: Download JUnit XML files
Expand Down
42 changes: 42 additions & 0 deletions examples/Python/pytest/TestModuleA.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from unittest import TestCase


class A:
_value: int

def __init__(self, value: int = 0):
self._value = value

@property
def Value(self) -> int:
return self._value

@Value.setter
def Value(self, value: int):
self._value = value


class Instantiation(TestCase):
def test_NoParameter(self):
a = A()

self.assertEqual(0, a.Value)

def test_Parameter(self):
a = A(5)

self.assertEqual(5, a.Value)


class Properties(TestCase):
def test_Getter(self):
a = A(10)

self.assertEqual(10, a.Value)

def test_Setter(self):
a = A(15)
self.assertEqual(15, a.Value)

a.Value = 20
self.assertEqual(20, a.Value)
52 changes: 52 additions & 0 deletions examples/Python/pytest/TestModuleB.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
from unittest import TestCase


class C:
_value: int

def __init__(self, value: int = 0):
self._value = value

def Add(self, value: int) -> int:
self._value += value
return self._value

def Sub(self, value: int) -> int:
self._value -= value
return self._value

@property
def Value(self) -> int:
return self._value

@Value.setter
def Value(self, value: int):
self._value = value


class Instantiation(TestCase):
def test_NoParameter(self):
a = C()

self.assertEqual(0, a.Value)

def test_Parameter(self):
a = C(5)

self.assertEqual(5, a.Value)


class Operations(TestCase):
def test_Add(self):
a = C(10)

self.assertEqual(10, a.Value)
self.assertEqual(15, a.Add(5))
self.assertEqual(15, a.Value)

def test_Sub(self):
a = C(10)

self.assertEqual(10, a.Value)
self.assertEqual(8, a.Sub(2))
self.assertEqual(8, a.Value)

0 comments on commit fa66901

Please sign in to comment.