Skip to content

Commit

Permalink
Add functional tests and GH workflows for it
Browse files Browse the repository at this point in the history
  • Loading branch information
vsivanandharao_expedia committed Jan 5, 2025
1 parent bb05d9d commit 671e919
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 0 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/functional-tests.yaml
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
6 changes: 6 additions & 0 deletions pyarchitecture/memory/windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class MEMORYSTATUSEX(ctypes.Structure):
>>> MEMORYSTATUSEX
References:
https://learn.microsoft.com/en-us/windows/win32/api/sysinfoapi/ns-sysinfoapi-memorystatusex
"""

_fields_ = [
Expand Down Expand Up @@ -50,6 +52,10 @@ def get_memory_info(_: str) -> Dict[str, int]:
used = total - available

# Virtual memory
# It is tied to the addressable memory space of your operating system and CPU architecture
# It is not tied to the physical memory installed on your system
# For example, a 64-bit processor can theoretically address 2^64 bytes of memory (16 exabytes)
# Practical limits are imposed by the OS. So, Windows typically uses a 48-bit address space, corresponding to 128 TB
virtual_total = memory_status.ullTotalVirtual
virtual_available = memory_status.ullAvailVirtual

Expand Down
47 changes: 47 additions & 0 deletions tests/functional.py
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()

0 comments on commit 671e919

Please sign in to comment.