Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,17 @@
"examples/minute_parity"
]
},
{
"name": "Python: Example Stand template",
"type": "debugpy",
"request": "launch",
"module": "hardpy.cli.cli",
"console": "integratedTerminal",
"args": [
"run",
"examples/stand_template"
]
},
{
"name": "Python: Example StandCloud",
"type": "debugpy",
Expand Down
5 changes: 3 additions & 2 deletions docs/documentation/pytest_hardpy.md
Original file line number Diff line number Diff line change
Expand Up @@ -1271,7 +1271,8 @@ Sets the group for a test case. Valid groups: `setup`, `main`, `teardown` (defau
**Example:**

```python
from hardpy.pytest_hardpy.utils.const import Group
from hardpy import Group

@pytest.mark.case_group(Group.SETUP)
def test_setup_case():
assert True
Expand All @@ -1289,7 +1290,7 @@ Sets the group for all test cases in a module. Valid groups: `setup`, `main`, `t

```python
import pytest
from hardpy.pytest_hardpy.utils.const import Group
from hardpy import Group

pytestmark = pytest.mark.module_group(Group.TEARDOWN)

Expand Down
3 changes: 3 additions & 0 deletions examples/stand_template/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Stand template

Example documentation: https://everypinio.github.io/hardpy/examples/stand_template/
28 changes: 28 additions & 0 deletions examples/stand_template/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import pytest
from utils.system_driver import SystemDriver

from hardpy import (
CouchdbConfig,
CouchdbLoader,
get_current_report,
)


@pytest.fixture(scope="session")
def system_driver():
example = SystemDriver()
yield example
example.disconnect()


def finish_executing():
report = get_current_report()
if report:
loader = CouchdbLoader(CouchdbConfig())
loader.load(report)


@pytest.fixture(scope="session", autouse=True)
def fill_actions_after_test(post_run_functions: list):
post_run_functions.append(finish_executing)
yield
109 changes: 109 additions & 0 deletions examples/stand_template/database/couchdb.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
; CouchDB Configuration Settings

; Custom settings should be made in this file. They will override settings
; in default.ini, but unlike changes made to default.ini, this file won't be
; overwritten on server upgrade.

[couchdb]
;max_document_size = 4294967296 ; bytes
;os_process_timeout = 5000

[couch_peruser]
; If enabled, couch_peruser ensures that a private per-user database
; exists for each document in _users. These databases are writable only
; by the corresponding user. Databases are in the following form:
; userdb-{hex encoded username}
;enable = true

; If set to true and a user is deleted, the respective database gets
; deleted as well.
;delete_dbs = true

; Set a default q value for peruser-created databases that is different from
; cluster / q
;q = 1

[chttpd]
;port = 5984
;bind_address = localhost

; Options for the MochiWeb HTTP server.
;server_options = [{backlog, 128}, {acceptor_pool_size, 16}]

; For more socket options, consult Erlang's module 'inet' man page.
;socket_options = [{sndbuf, 262144}, {nodelay, true}]

enable_cors=true

[httpd]
; NOTE that this only configures the "backend" node-local port, not the
; "frontend" clustered port. You probably don't want to change anything in
; this section.
; Uncomment next line to trigger basic-auth popup on unauthorized requests.
;WWW-Authenticate = Basic realm="administrator"

; Uncomment next line to set the configuration modification whitelist. Only
; whitelisted values may be changed via the /_config URLs. To allow the admin
; to change this value over HTTP, remember to include {httpd,config_whitelist}
; itself. Excluding it from the list would require editing this file to update
; the whitelist.
;config_whitelist = [{httpd,config_whitelist}, {log,level}, {etc,etc}]

[cors]
origins = *
methods = GET, PUT, POST, HEAD, DELETE
credentials = true
headers = accept, authorization, content-type, origin, referer, x-csrf-token


[ssl]
;enable = true
;cert_file = /full/path/to/server_cert.pem
;key_file = /full/path/to/server_key.pem
;password = somepassword

; set to true to validate peer certificates
;verify_ssl_certificates = false

; Set to true to fail if the client does not send a certificate. Only used if verify_ssl_certificates is true.
;fail_if_no_peer_cert = false

; Path to file containing PEM encoded CA certificates (trusted
; certificates used for verifying a peer certificate). May be omitted if
; you do not want to verify the peer.
;cacert_file = /full/path/to/cacertf

; The verification fun (optional) if not specified, the default
; verification fun will be used.
;verify_fun = {Module, VerifyFun}

; maximum peer certificate depth
;ssl_certificate_max_depth = 1

; Reject renegotiations that do not live up to RFC 5746.
;secure_renegotiate = true

; The cipher suites that should be supported.
; Can be specified in erlang format "{ecdhe_ecdsa,aes_128_cbc,sha256}"
; or in OpenSSL format "ECDHE-ECDSA-AES128-SHA256".
;ciphers = ["ECDHE-ECDSA-AES128-SHA256", "ECDHE-ECDSA-AES128-SHA"]

; The SSL/TLS versions to support
;tls_versions = [tlsv1, 'tlsv1.1', 'tlsv1.2']

; To enable Virtual Hosts in CouchDB, add a vhost = path directive. All requests to
; the Virtual Host will be redirected to the path. In the example below all requests
; to http://example.com/ are redirected to /database.
; If you run CouchDB on a specific port, include the port number in the vhost:
; example.com:5984 = /database
[vhosts]
;example.com = /database/

; To create an admin account uncomment the '[admins]' section below and add a
; line in the format 'username = password'. When you next start CouchDB, it
; will change the password to a hash (so that your passwords don't linger
; around in plain-text files). You can add more admin accounts with more
; 'username = password' lines. Don't forget to restart CouchDB after
; changing this.
[admins]
;admin = mysecretpassword
13 changes: 13 additions & 0 deletions examples/stand_template/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: "3.8"

services:
couchserver:
image: couchdb:3.4
ports:
- "5984:5984"
environment:
COUCHDB_USER: dev
COUCHDB_PASSWORD: dev
volumes:
- ./database/dbdata:/opt/couchdb/data
- ./database/couchdb.ini:/opt/couchdb/etc/local.ini
13 changes: 13 additions & 0 deletions examples/stand_template/hardpy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
title = "HardPy TOML config"
tests_name = "stand_template"

[database]
user = "dev"
password = "dev"
host = "localhost"
port = 5984

[frontend]
host = "localhost"
port = 8000
language = "en"
3 changes: 3 additions & 0 deletions examples/stand_template/pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[pytest]
addopts = --hardpy-pt
--hardpy-db-url http://dev:dev@localhost:5984/
1 change: 1 addition & 0 deletions examples/stand_template/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
psutil
48 changes: 48 additions & 0 deletions examples/stand_template/test_1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import pytest

from hardpy import (
Group,
Instrument,
set_instrument,
set_process_name,
set_process_number,
set_stand_name,
set_stand_number,
set_stand_revision,
)

pytestmark = [
pytest.mark.module_name("Test run information"),
pytest.mark.module_group(Group.SETUP),
]


@pytest.mark.case_name("Process")
def test_process_info():
process_name = "System Test"
process_number = 3
set_process_name(process_name)
set_process_number(process_number)


@pytest.mark.case_name("Stand")
def test_stand_info():
stand_name = "System check"
stand_number = 1
stand_revision = "HW1.1"
set_stand_name(stand_name)
set_stand_number(stand_number)
set_stand_revision(stand_revision)


@pytest.mark.case_name("Instrument")
def test_instrument_info():
instrument = Instrument(name="System driver", revision="2.0")
set_instrument(instrument)


def test_dut_info():
part_number = "part_number_1"
type = "PCBA"
revision = "REV1.0"

19 changes: 19 additions & 0 deletions examples/stand_template/test_2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import pytest
from utils import ProjectErrorCode, SystemDriver

from hardpy import ErrorCode, Group

pytestmark = [
pytest.mark.module_name("Test run information"),
pytest.mark.module_group(Group.SETUP),
]


@pytest.mark.case_name("System driver connect")
@pytest.mark.critical
def test_system_driver_connect(system_driver: SystemDriver):
is_connected = system_driver.connect()
assert is_connected, ErrorCode(
ProjectErrorCode.SYSTEM_DRIVER_NOT_CONNECTED,
"System driver not connected",
)
4 changes: 4 additions & 0 deletions examples/stand_template/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from utils.error_code import ProjectErrorCode
from utils.system_driver import SystemDriver

__all__ = ["ProjectErrorCode", "SystemDriver"]
8 changes: 8 additions & 0 deletions examples/stand_template/utils/error_code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from enum import Enum


class ProjectErrorCode(Enum):
"""Project error codes."""

SYSTEM_DRIVER_NOT_CONNECTED = 1
ODD_MINUTE = 2
25 changes: 25 additions & 0 deletions examples/stand_template/utils/system_driver.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import datetime
import psutil


class SystemDriver:
"""System driver."""

def __init__(self):
pass

def connect(self) -> bool:
return True

def disconnect(self) -> bool:
return True

@property
def current_minute(self) -> int:
"""Example of driver method."""
current_time = datetime.datetime.now()
return int(current_time.strftime("%M"))

@property
def cpu_freq(self) -> float:
return psutil.cpu_freq()
2 changes: 2 additions & 0 deletions hardpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
ComparisonOperation,
DialogBox,
DuplicateParameterError,
Group,
HTMLComponent,
ImageComponent,
Instrument,
Expand All @@ -74,6 +75,7 @@
"DialogBox",
"DuplicateParameterError",
"ErrorCode",
"Group",
"HTMLComponent",
"ImageComponent",
"Instrument",
Expand Down
Loading