Skip to content

Commit

Permalink
low_voltage new port and debug pytest (#5)
Browse files Browse the repository at this point in the history
* test coverage

* test coverage_main, dev

* test coverage dev

* code-cov issue

* fix indentation

* update readme

* readme updated

* test codecov

* remove push dev

* extracted OS generated files

* test new port

* new port

* pytest

* pytest2

* pytest

* pytest

* pytest

* pytest

* back to original yaml

* actionv2

* pytest&&mqtthost key error

* pytest solved
  • Loading branch information
cdozen authored Jul 13, 2023
1 parent 5587dc1 commit 5e031dd
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docker-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
type=semver,pattern={{major}}.{{minor}}
-
name: Login to ghcr
uses: docker/login-action@v1
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
Expand Down
8 changes: 6 additions & 2 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ name: Python package

on:
pull_request:
branches: [ main, dev ]
branches: [ main, dev]

jobs:
build:
Expand All @@ -32,7 +32,11 @@ jobs:
run: |
python3 -m pip install -r requirements/local.txt
python3 -m pip install -e .
- name: Print Python environment
run: |
python3 --version
python3 -m pip list
- name: Docker-compose start mqtt and low_voltage
run: |
cd docker/tedd_low_voltage
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ __pycache__/
# C extensions
*.so

# OS generated files #
######################
.DS_Store
**/.DS_Store

# Distribution / packaging
.Python
build/
Expand Down
7 changes: 2 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#FROM centos:centos7
FROM --platform=linux/amd64 centos:centos7
FROM centos:centos7
#FROM --platform=linux/amd64 centos:centos7

WORKDIR /usr/app

Expand Down Expand Up @@ -39,6 +39,3 @@ RUN yum install -y libusb && \
COPY requirements ./requirements
RUN python3 -m pip install --no-cache-dir -r requirements/docker.txt

#COPY setup.py .
#RUN python3 -m pip install -e .

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ python3 -m pip install -e .
To create centos:low_votage image with necessary packages.

```
docker build -t centos:tedd_dcs_low_voltage .
docker build -t low_voltage:centos .
```

## Docker stack
Expand Down
Empty file added __init__.py
Empty file.
Empty file added low_voltage/__init__.py
Empty file.
2 changes: 1 addition & 1 deletion low_voltage/lv-HMP/HMP4040.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import pyvisa as visa

rm = visa.ResourceManager("/usr/lib64/librsvisa.so@ivi")
HMP4040 = rm.open_resource("TCPIP::192.168.1.203::10002::SOCKET")
HMP4040 = rm.open_resource("TCPIP::192.168.1.202::5025::SOCKET")
HMP4040.read_termination = "\n"
HMP4040.write_termination = "\n"
HMP4040.write("*IDN?")
Expand Down
2 changes: 1 addition & 1 deletion low_voltage/lv-HMP/hmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class HMP(object):
"/usr/lib64/librsvisa.so@ivi"
) # use the default backend(NI) visa shared library.
HMP4040 = rm.open_resource(
"TCPIP::192.168.1.202::10002::SOCKET"
"TCPIP::192.168.1.202::5025::SOCKET"
) # connect to R&S HMP4040 device via TCPIP
num_of_channels = 5

Expand Down
24 changes: 14 additions & 10 deletions low_voltage/mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@
from low_voltage.utils.logger import logger


mqtt_host = os.environ["MQTT_HOST"]
# mqtt_host = os.environ["MQTT_HOST"]
def connect_to_mqtt():
mqtt_host = os.environ.get("MQTT_HOST")
if mqtt_host is None:
logger.error("MQTT_HOST environment variable is not set.")
return

def on_connect(client, userdata, flags, rc):
# Subscribing in on_connect() means that if we lose the connection and
# reconnect then subscriptions will be renewed.
logger.info(f"connected to mqtt broker: {mqtt_host}")

def on_connect(client, userdata, flags, rc):
# Subscribing in on_connect() means that if we lose the connection and
# reconnect then subscriptions will be renewed.
logger.info(f"Connected to mqtt broker: {mqtt_host}")


client = mqtt.Client()
client.on_connect = on_connect
client.connect(mqtt_host, 1883, 60)
client = mqtt.Client()
client.on_connect = on_connect
client.connect(mqtt_host, 1883, 60)
return client
7 changes: 3 additions & 4 deletions unittests/test_mqtt.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import pytest
from fixtures import env
import low_voltage.mqtt as connect_to_mqtt


@pytest.fixture
def mqtt(env):
import low_voltage.mqtt as mqtt_mod

return mqtt_mod
return connect_to_mqtt.connect_to_mqtt()


def test_connect(mqtt):
assert True
assert mqtt is not None

0 comments on commit 5e031dd

Please sign in to comment.