-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add functional tests and GH workflows for it
- Loading branch information
vsivanandharao_expedia
committed
Jan 5, 2025
1 parent
bb05d9d
commit 671e919
Showing
3 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
name: functional-tests | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
paths: | ||
- '**/*.py' | ||
workflow_dispatch: | ||
|
||
jobs: | ||
functional-tests: | ||
strategy: | ||
matrix: | ||
platform: | ||
- release_for: linux-amd64 | ||
- release_for: darwin-amd64 | ||
- release_for: windows-amd64 | ||
name: Test functionality on ${{ matrix.platform.release_for }} | ||
runs-on: | ||
- thevickypedia-default | ||
- ${{ matrix.platform.release_for }} | ||
steps: | ||
- name: Checkout Repository | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Set up Python | ||
if: matrix.platform.release_for != 'darwin-amd64' | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: '3.x' | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
export PYTHONPATH="$(pwd):$PYTHONPATH" | ||
python -m pip install . | ||
shell: bash | ||
|
||
- name: Run functional tests | ||
run: python functional.py | ||
working-directory: tests | ||
shell: bash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import platform | ||
from typing import Set, NoReturn | ||
|
||
import pyarchitecture | ||
|
||
|
||
def assert_disks(valid_keys: Set[str]) -> None | NoReturn: | ||
"""Assert disks.""" | ||
disk_info = pyarchitecture.disks.get_all_disks() | ||
assert disk_info | ||
for disk in disk_info: | ||
assert set(disk.keys()) == valid_keys | ||
# No assertion for values since they can be null in VMs | ||
|
||
|
||
def assert_cpu() -> None | NoReturn: | ||
"""Assert CPU output.""" | ||
assert pyarchitecture.cpu.get_cpu_info() | ||
|
||
|
||
def assert_memory(valid_keys: Set[str]) -> None | NoReturn: | ||
mem_info = pyarchitecture.memory.get_memory_info() | ||
assert set(mem_info.keys()) == valid_keys, f"{set(mem_info.keys())} != {valid_keys}" | ||
assert all(mem_info.values()) | ||
|
||
|
||
def main() -> None | NoReturn: | ||
"""Main entrypoint.""" | ||
system = platform.system().lower() | ||
disk_keys = {"name", "size", "device_id", "mountpoints"} | ||
memory_keys = {"total", "free", "used", "available"} | ||
if system == "darwin": | ||
disk_keys.add("node") | ||
memory_keys.update(("swap_total", "swap_used", "swap_free")) | ||
if system == "linux": | ||
memory_keys.update(("swap_total", "swap_used", "swap_free")) | ||
if system == "windows": | ||
# Windows doesn't have a distinction between free and available memory | ||
memory_keys.remove("free") | ||
memory_keys.update(("virtual_total", "virtual_available")) | ||
assert_disks(disk_keys) | ||
assert_cpu() | ||
assert_memory(memory_keys) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |