Skip to content

Commit

Permalink
Merge pull request #3109 from Bravo555/format/robotidy
Browse files Browse the repository at this point in the history
format: Reformat Robot Framework files with robotframework-tidy
  • Loading branch information
Bravo555 authored Sep 10, 2024
2 parents e4ff79b + 9e4df63 commit c52675a
Show file tree
Hide file tree
Showing 96 changed files with 3,281 additions and 1,898 deletions.
24 changes: 23 additions & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,43 @@ check-tools:
exit 1
fi

# Format code
# Format code and tests
format: check-tools
#!/usr/bin/env bash
set -e
cargo +nightly fmt
taplo fmt

if [ ! -d tests/RobotFramework/.venv ]; then
just -f {{justfile()}} setup-integration-test
fi
cd tests/RobotFramework
source .venv/bin/activate
echo Formatting tests...
invoke format-tests

# Check code formatting
format-check: check-tools
cargo +nightly fmt -- --check
taplo fmt --check

# Check code
check TARGET=DEFAULT_TARGET:
#!/usr/bin/env bash
set -e
{{CARGO}} check --target {{TARGET}}
{{CARGO}} clippy --all-targets --all-features --target {{TARGET}}

if [ ! -d tests/RobotFramework/.venv ]; then
just -f {{justfile()}} setup-integration-test
fi
cd tests/RobotFramework
source .venv/bin/activate
echo Checking tests...
invoke lint-tests

# Release, building all binaries and debian packages
release *ARGS:
ci/build_scripts/build.sh {{ARGS}}
Expand Down
36 changes: 36 additions & 0 deletions tests/RobotFramework/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# See the robocop rules list for more information about the linting rules:
# https://robocop.readthedocs.io/en/stable/rules_list.html
[tool.robocop]
exclude = [
# Docs
"missing-doc-suite",
"missing-doc-test-case",
"missing-doc-keyword",

# Size
"too-long-test-case",
"file-too-long",
"line-too-long",
"too-many-calls-in-test-case",
"too-many-calls-in-keyword",
"too-many-arguments",

# Naming
"not-allowed-char-in-name",
# Some Keywords are more descriptive with the usage of underscore
# as they can include important info like 'c8y_Firmware'
"underscore-in-keyword-name",
"non-local-variables-should-be-uppercase",
"section-variable-not-uppercase",
"inconsistent-variable-name",
"too-long-keyword",

# Styling
"not-capitalized-test-case-title",
"wrong-case-in-keyword-name",
]

configure = [
"line-too-long:line_length:220",
"todo-in-comment:severity:I"
]
2 changes: 2 additions & 0 deletions tests/RobotFramework/requirements/requirements.dev.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
black~=24.4.2
invoke~=2.2.0
pylint~=3.1.0
robotframework-tidy~=4.14.0
robotframework-robocop~=5.4.0
25 changes: 18 additions & 7 deletions tests/RobotFramework/resources/common.resource
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
*** Variables ***
*** Settings ***
Documentation Test parameterization

*** Variables ***
# Adapter settings
${DEVICE_ADAPTER} %{DEVICE_ADAPTER=docker}
&{SSH_CONFIG} hostname=%{SSH_CONFIG_HOSTNAME= } username=%{SSH_CONFIG_USERNAME= } password=%{SSH_CONFIG_PASSWORD= } skip_bootstrap=False bootstrap_script=%{SSH_CONFIG_BOOTSTRAP_SCRIPT= } configpath=%{SSH_CONFIG_CONFIGPATH= }
&{DOCKER_CONFIG} image=%{DOCKER_CONFIG_IMAGE=debian-systemd} bootstrap_script=%{DOCKER_CONFIG_BOOTSTRAP_SCRIPT=/setup/bootstrap.sh}
&{LOCAL_CONFIG} skip_bootstrap=False bootstrap_script=%{LOCAL_CONFIG_BOOTSTRAP_SCRIPT= }
${DEVICE_ADAPTER} %{DEVICE_ADAPTER=docker}
&{SSH_CONFIG}
... hostname=%{SSH_CONFIG_HOSTNAME= }
... username=%{SSH_CONFIG_USERNAME= }
... password=%{SSH_CONFIG_PASSWORD= }
... skip_bootstrap=False
... bootstrap_script=%{SSH_CONFIG_BOOTSTRAP_SCRIPT= }
... configpath=%{SSH_CONFIG_CONFIGPATH= }
&{DOCKER_CONFIG}
... image=%{DOCKER_CONFIG_IMAGE=debian-systemd}
... bootstrap_script=%{DOCKER_CONFIG_BOOTSTRAP_SCRIPT=/setup/bootstrap.sh}
&{LOCAL_CONFIG} skip_bootstrap=False bootstrap_script=%{LOCAL_CONFIG_BOOTSTRAP_SCRIPT= }

# Cumulocity settings
&{C8Y_CONFIG} host=%{C8Y_BASEURL= } username=%{C8Y_USER= } password=%{C8Y_PASSWORD= }
&{C8Y_CONFIG} host=%{C8Y_BASEURL= } username=%{C8Y_USER= } password=%{C8Y_PASSWORD= }

# AWS settings
&{AWS_CONFIG} host=%{AWS_URL= }
&{AWS_CONFIG} host=%{AWS_URL= }
15 changes: 15 additions & 0 deletions tests/RobotFramework/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,27 @@ def lint(c):
"""Run linter"""
c.run(f"{sys.executable} -m pylint libraries")

@task
def lint_tests(c, threshold="W"):
"""Run RobotFramework Test Linter
Example:
$ invoke lint-tests --threshold I
# Run linting and include Info level messages
"""
c.run(f"{sys.executable} -m robocop --report rules_by_error_type --threshold {threshold}")

@task(name="format")
def formatcode(c):
"""Format python code"""
c.run(f"{sys.executable} -m black libraries")

@task
def format_tests(c):
"""Format RobotFramework tests
"""
c.run(f"{sys.executable} -m robotidy tests")


@task(name="reports")
def start_server(c, port=9000):
Expand Down
42 changes: 22 additions & 20 deletions tests/RobotFramework/tasks/E2E_Tutorials/Connect_to_c8y.robot
Original file line number Diff line number Diff line change
@@ -1,36 +1,38 @@
#Command to execute: robot -d \results --timestampoutputs --log health_tedge_mapper.html --report NONE health_tedge_mapper.robot
*** Comments ***
# Command to execute: robot -d \results --timestampoutputs --log health_tedge_mapper.html --report NONE health_tedge_mapper.robot


*** Settings ***
Resource ../../resources/common.resource
Library ThinEdgeIO
Library String
Library Cumulocity
Suite Teardown Get Logs
Resource ../../resources/common.resource
Library String
Library ThinEdgeIO
Library Cumulocity

Suite Teardown Get Logs

*** Variables ***

${DEVICE_SN}
*** Variables ***
${DEVICE_SN} ${EMPTY}


*** Tasks ***

Install thin-edge.io on your device
${device_sn}= Setup skip_bootstrap=True
${device_sn}= Setup skip_bootstrap=True
Set Suite Variable $DEVICE_SN ${device_sn}
Uninstall tedge with purge
Clear previous downloaded files if any
Install thin-edge.io

Set the URL of your Cumulocity IoT tenant
${HOSTNAME}= Replace String Using Regexp ${C8Y_CONFIG.host} ^.*:// ${EMPTY}
${HOSTNAME}= Strip String ${HOSTNAME} characters=/
${HOSTNAME}= Replace String Using Regexp ${C8Y_CONFIG.host} ^.*:// ${EMPTY}
${HOSTNAME}= Strip String ${HOSTNAME} characters=/
Execute Command sudo tedge config set c8y.url ${HOSTNAME} # Set the URL of your Cumulocity IoT tenant

Create the certificate
Execute Command sudo tedge cert create --device-id ${DEVICE_SN}

#You can then check the content of that certificate.
${output}= Execute Command sudo tedge cert show #You can then check the content of that certificate.
# You can then check the content of that certificate.
${output}= Execute Command sudo tedge cert show # You can then check the content of that certificate.
Should Contain ${output} Device certificate: /etc/tedge/device-certs/tedge-certificate.pem
Should Contain ${output} Subject: CN=${DEVICE_SN}, O=Thin Edge, OU=Test Device
Should Contain ${output} Issuer: CN=${DEVICE_SN}, O=Thin Edge, OU=Test Device
Expand All @@ -43,7 +45,7 @@ tedge cert upload c8y command
Sleep 3s # Wait for cert to be processed/distributed to all cores (in Cumulocity IoT)

Connect the device
${output}= Execute Command sudo tedge connect c8y #You can then check the content of that certificate.
${output}= Execute Command sudo tedge connect c8y # You can then check the content of that certificate.
Sleep 3s
Should Contain ${output} Checking if systemd is available.
Should Contain ${output} Checking if configuration for requested bridge already exists.
Expand All @@ -67,7 +69,7 @@ Connect the device
Should Contain ${output} tedge-agent service successfully started and enabled!

Sending your first telemetry data
Execute Command tedge mqtt pub c8y/s/us 211,20 #Set the URL of your Cumulocity IoT tenant
Execute Command tedge mqtt pub c8y/s/us 211,20 # Set the URL of your Cumulocity IoT tenant

Download the measurements report file
Device Should Exist ${DEVICE_SN}
Expand All @@ -78,14 +80,14 @@ Monitor the device
Execute Command sudo apt-get update && sudo apt-get install libmosquitto1 -y
Execute Command sudo apt-get install collectd-core -y
# Configure collectd
Execute Command sudo cp /etc/tedge/contrib/collectd/collectd.conf /etc/collectd/collectd.conf; sudo systemctl restart collectd
#Enable Collectd
Execute Command
... sudo cp /etc/tedge/contrib/collectd/collectd.conf /etc/collectd/collectd.conf; sudo systemctl restart collectd
# Enable Collectd
Execute Command sudo systemctl start tedge-mapper-collectd && sudo systemctl enable tedge-mapper-collectd
${measure} Device Should Have Measurements minimum=1
${measure}= Device Should Have Measurements minimum=1


*** Keywords ***

Uninstall tedge with purge
Execute Command wget https://raw.githubusercontent.com/thin-edge/thin-edge.io/main/uninstall-thin-edge_io.sh
Execute Command chmod a+x uninstall-thin-edge_io.sh
Expand Down
Loading

0 comments on commit c52675a

Please sign in to comment.