Skip to content
Open
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
23 changes: 23 additions & 0 deletions news/gui-test.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
**Added:**

* Added unit test codes for the GUI

**Changed:**

* <news item>

**Deprecated:**

* <news item>

**Removed:**

* <news item>

**Fixed:**

* <news item>

**Security:**

* <news item>
72 changes: 40 additions & 32 deletions scripts/install_from_local.bat
Original file line number Diff line number Diff line change
@@ -1,39 +1,47 @@
:: This batch script will install python 3.8, pytentiostat and it's necessary packages
:: This batch script will install Python 3.12, pytentiostat, and its necessary packages
@echo off
cd ../local_install
echo Installing python
START /WAIT python-3.8.1-amd64
echo Installing Python 3.12
START /WAIT python-3.12.8-amd64.exe
python --version
if errorlevel 1 goto NoPython
pip install whls/pytz-2019.3-py2.py3-none-any.whl
pip install whls/kiwisolver-1.1.0-cp38-none-win_amd64.whl
pip install whls/six-1.14.0-py2.py3-none-any.whl
pip install whls/pyparsing-2.4.6-py2.py3-none-any.whl
pip install whls/python_dateutil-2.8.1-py2.py3-none-any.whl
pip install whls/pyserial-3.4-py2.py3-none-any.whl
pip install whls/pyFirmata-1.1.0-py2.py3-none-any.whl
pip install whls/numpy-1.18.1-cp38-cp38-win_amd64.whl
pip install whls/pandas-0.25.3-cp38-cp38-win_amd64.whl
pip install whls/PyYAML-5.3-cp38-cp38-win_amd64.whl
pip install whls/urllib3-1.25.8-py2.py3-none-any.whl
pip install whls/py-1.8.1-py2.py3-none-any.whl
pip install whls/idna-2.8-py2.py3-none-any.whl
pip install whls/chardet-3.0.4-py2.py3-none-any.whl
pip install whls/certifi-2019.11.28-py2.py3-none-any.whl
pip install whls/pluggy-0.13.1-py2.py3-none-any.whl
pip install whls/packaging-20.0-py2.py3-none-any.whl
pip install whls/more_itertools-8.1.0-py3-none-any.whl
pip install whls/wcwidth-0.1.8-py2.py3-none-any.whl
pip install whls/atomicwrites-1.3.0-py2.py3-none-any.whl
pip install whls/attrs-19.3.0-py2.py3-none-any.whl
pip install whls/cycler-0.10.0-py2.py3-none-any.whl
pip install whls/matplotlib-3.1.2-cp38-cp38-win_amd64.whl
pip install whls/coverage-5.0.3.tar.gz
pip install whls/colorama-0.4.3-py2.py3-none-any.whl
pip install whls/requests-2.22.0-py2.py3-none-any.whl
pip install whls/pytest-5.3.4-py3-none-any.whl
pip install whls/mock-3.0.5-py2.py3-none-any.whl
pip install whls/codecov-2.0.15-py2.py3-none-any.whl

:: Upgrade pip to the latest version
python -m pip install --upgrade pip

:: Install necessary packages
pip install pytentiostat
pip install pytz
pip install kiwisolver
pip install six
pip install pyparsing
pip install python_dateutil
pip install pyserial
pip install pyFirmata
pip install numpy
pip install pandas
pip install PyYAML
pip install urllib3
pip install py
pip install idna
pip install chardet
pip install certifi
pip install pluggy
pip install packaging
pip install more_itertools
pip install wcwidth
pip install atomicwrites
pip install attrs
pip install cycler
pip install matplotlib
pip install coverage
pip install colorama
pip install requests
pip install pytest
pip install mock
pip install codecov
pip install pyside6

cd ..
python setup.py install
@pause
Expand Down
40 changes: 39 additions & 1 deletion scripts/pytentiostat
Original file line number Diff line number Diff line change
@@ -1,4 +1,42 @@
#!/usr/bin/env python
import argparse
from importlib.metadata import PackageNotFoundError, version

from pytentiostat.main import main

main()

def print_version():
"""Print the version of the pytentiostat package."""
try:
pkg_version = version("pytentiostat")
print(f"Pytentiostat version: {pkg_version}")
except PackageNotFoundError:
print("Error: pytentiostat package is not installed.")


def main_wrapper():
# Set up argument parsing
parser = argparse.ArgumentParser(
description="Pytentiostat Command Line Interface"
)
parser.add_argument(
"--version",
action="store_true",
help="Show the version of pytentiostat",
)
parser.add_argument(
"--help", action="help", help="Show this help message and exit"
)

# Parse the arguments
args = parser.parse_args()

# Check if the version flag is set
if args.version:
print_version()
else:
main() # Call the main function of the pytentiostat application


if __name__ == "__main__":
main_wrapper()
13 changes: 11 additions & 2 deletions scripts/pytentiostat.bat
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
@echo off
call :s_which py.exe

if not "%_path%" == "" (
py -3 -m pytentiostat %*
if "%1" == "--version" (
py -3 -c "import pytentiostat; print(pytentiostat.__version__)"
) else (
py -3 -m pytentiostat %*
)
) else (
python -m pytentiostat %*
if "%1" == "--version" (
python -c "import pytentiostat; print(pytentiostat.__version__)"
) else (
python -m pytentiostat %*
)
)

goto :eof
Expand Down
29 changes: 29 additions & 0 deletions src/GUI/gui_test/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#General parameters to edit for an experiment
general_parameters:
experiment_type: LSV
rest_time: 0.5 #s
step_number: 100
data_output_filename: testfile
data_output_path: desktop
linear_sweep_voltammetry:
start_voltage: 0 #V
end_voltage: 1 #V
sweep_rate: 100 #mV/s
cyclic_voltammetry:
start_voltage: 0.5 #V
first_turnover_voltage: 1 #V
second_turnover_voltage: 0 #V
sweep_rate: 100 #mV/s
number_of_cycles: 1
chronoamperometry:
voltage: 1 #V
time: 15 #s

#Only advanced users should edit advanced parameters
advanced_parameters:
conversion_factor: 4.798
setpoint_gain: 1.03
setpoint_offset: 0
shunt_resistor: 0.202 #mOhm
time_step: 0.003 #s
average_number: 9
65 changes: 65 additions & 0 deletions src/GUI/gui_test/test_adv_params_gui.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import unittest

from PySide6 import QtWidgets

from src.GUI.code.Adv_params_GUI import Ui_Adv_Params


class TestUiAdvParams(unittest.TestCase):
def setUp(self):
"""Set up the application and the UI before each test."""
self.app = QtWidgets.QApplication([])
self.window = QtWidgets.QMainWindow()
self.ui = Ui_Adv_Params()
self.ui.setupUi(self.window)

def test_window_title(self):
"""Test if the window title is set correctly."""
self.assertEqual(self.window.windowTitle(), "Adv Params")

def test_labels_exist(self):
"""Test if all labels are created and have the correct text."""
self.assertIsNotNone(self.ui.experiment_conversion_factor_label)
self.assertIsNotNone(self.ui.experiment_averag_number_label)
self.assertIsNotNone(self.ui.experiment_shunt_resistor_label)
self.assertIsNotNone(self.ui.advanced_parameters_label)
self.assertIsNotNone(self.ui.experiment_setpoint_gain_label)
self.assertIsNotNone(self.ui.experiment_setpoint_offset_label)
self.assertIsNotNone(self.ui.experiment_time_step_label)

self.assertEqual(self.ui.experiment_conversion_factor_label.text(),
'<html><head/><body><p align="center">Conversion Factor</p></body></html>')
self.assertEqual(self.ui.experiment_averag_number_label.text(),
'<html><head/><body><p align="center">Average Number</p></body></html>')
self.assertEqual(self.ui.experiment_shunt_resistor_label.text(),
'<html><head/><body><p align="center">Shunt Resistor /mohm</p></body></html>')
self.assertEqual(self.ui.advanced_parameters_label.text(),
'<html><head/><body><p align="center">Advanced Parameters</p></body></html>')
self.assertEqual(self.ui.experiment_setpoint_gain_label.text(),
'<html><head/><body><p align="center">Setpoint Gain</p></body></html>')
self.assertEqual(self.ui.experiment_setpoint_offset_label.text(),
'<html><head/><body><p align="center">Setpoint Offset</p></body></html>')
self.assertEqual(self.ui.experiment_time_step_label.text(),
'<html><head/><body><p align="center">Time Step /s</p></body></html>')

def test_line_edits_exist(self):
"""Test if all line edit fields are created."""
self.assertIsNotNone(self.ui.experiment_setpoint_gain)
self.assertIsNotNone(self.ui.experiment_shunt_resistor)
self.assertIsNotNone(self.ui.experiment_setpoint_offset)
self.assertIsNotNone(self.ui.experiment_time_step)
self.assertIsNotNone(self.ui.experiment_averag_number)
self.assertIsNotNone(self.ui.experiment_conversion_factor)

def test_save_button_exists(self):
"""Test if the save button is created."""
self.assertIsNotNone(self.ui.save_experiment_file_button)
self.assertEqual(self.ui.save_experiment_file_button.text(), "Save ")

def tearDown(self):
"""Clean up after each test."""
self.window.close()


if __name__ == "__main__":
unittest.main()
76 changes: 76 additions & 0 deletions src/GUI/gui_test/test_ca_gui.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import unittest

from PySide6 import QtWidgets

from src.GUI.code.CA_GUI import Ui_CA


class TestUiCA(unittest.TestCase):
def setUp(self):
"""Set up the application and the UI before each test."""
self.app = QtWidgets.QApplication([])
self.window = QtWidgets.QMainWindow()
self.ui = Ui_CA()
self.ui.setupUi(self.window)

def test_window_title(self):
"""Test if the window title is set correctly."""
self.assertEqual(self.window.windowTitle(), "CA Experiment Creator")

def test_labels_exist(self):
"""Test if all labels are created and have the correct text."""
self.assertIsNotNone(self.ui.rest_time_label)
self.assertIsNotNone(self.ui.experiment_type_label)
self.assertIsNotNone(self.ui.experiment_time_label)
self.assertIsNotNone(self.ui.general_parameters_label)
self.assertIsNotNone(self.ui.output_filename_label)
self.assertIsNotNone(self.ui.step_number_label)
self.assertIsNotNone(self.ui.experiment_parameters_label)
self.assertIsNotNone(self.ui.voltage_label)

self.assertEqual(self.ui.rest_time_label.text(),
'<html><head/><body><p align="center">Rest Time</p></body></html>')
self.assertEqual(self.ui.experiment_type_label.text(),
'<html><head/><body><p align="center">Experiment Type</p></body></html>')
self.assertEqual(self.ui.experiment_time_label.text(),
'<html><head/><body><p align="center">Experiment Time</p></body></html>')
self.assertEqual(self.ui.general_parameters_label.text(),
'<html><head/><body><p align="center">General Parameters</p></body></html>')
self.assertEqual(self.ui.output_filename_label.text(),
'<html><head/><body><p align="center">Output Filename</p></body></html>')
self.assertEqual(self.ui.step_number_label.text(),
'<html><head/><body><p align="center">Step Number</p></body></html>')
self.assertEqual(self.ui.experiment_parameters_label.text(),
'<html><head/><body><p align="center">Experiment Parameters</p></body></html>')
self.assertEqual(self.ui.voltage_label.text(),
'<html><head/><body><p align="center">Voltage</p></body></html>')

def test_line_edits_exist(self):
"""Test if all line edit fields are created."""
self.assertIsNotNone(self.ui.experiment_step_number)
self.assertIsNotNone(self.ui.experiment_time)
self.assertIsNotNone(self.ui.experiment_voltage)
self.assertIsNotNone(self.ui.experiment_rest_time)
self.assertIsNotNone(self.ui.experiment_file_name)
self.assertIsNotNone(self.ui.experiment_file_path)
self.assertIsNotNone(self.ui.experiment_duration)

def test_buttons_exist(self):
"""Test if all buttons are created."""
self.assertIsNotNone(self.ui.select_output_filepath_button)
self.assertIsNotNone(self.ui.advanced_parameters_button)
self.assertIsNotNone(self.ui.save_experiment_file_button)
self.assertIsNotNone(self.ui.generate_preview_button)

self.assertEqual(self.ui.select_output_filepath_button.text(), "Output Filepath")
self.assertEqual(self.ui.advanced_parameters_button.text(), "Advanced Parameters")
self.assertEqual(self.ui.save_experiment_file_button.text(), "Save Experiment File")
self.assertEqual(self.ui.generate_preview_button.text(), "Generate Preview")

def tearDown(self):
"""Clean up after each test."""
self.window.close()


if __name__ == "__main__":
unittest.main()
Loading