mirror of
https://github.com/SeedSigner/seedsigner.git
synced 2026-10-05 15:08:25 +00:00
Adds initial test suite setup
This commit is contained in:
@@ -172,3 +172,7 @@ sudo reboot
|
||||
It will take about a minute after the Pi is powered on for the GUI to launch -- be patient!
|
||||
|
||||
_Reminder: If you used option #2, [return the guide](docs/usb_relay.md) to remove the internet access over USB configuration._
|
||||
|
||||
|
||||
## Run the tests
|
||||
see: [tests/README.md](tests/README.md)
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
[pytest]
|
||||
testpaths = tests
|
||||
@@ -0,0 +1,26 @@
|
||||
import setuptools
|
||||
|
||||
with open("README.md", "r", encoding="utf-8") as fh:
|
||||
long_description = fh.read()
|
||||
|
||||
setuptools.setup(
|
||||
name="seedsigner",
|
||||
version="0.4.1",
|
||||
author="SeedSigner",
|
||||
author_email="author@example.com",
|
||||
description="Build an offline, airgapped Bitcoin signing device for less than $50!",
|
||||
long_description=long_description,
|
||||
long_description_content_type="text/markdown",
|
||||
url="https://github.com/SeedSigner/seedsigner",
|
||||
project_urls={
|
||||
"Bug Tracker": "https://github.com/SeedSigner/seedsigner/issues",
|
||||
},
|
||||
classifiers=[
|
||||
"Programming Language :: Python :: 3",
|
||||
"License :: OSI Approved :: MIT License",
|
||||
"Operating System :: OS Independent",
|
||||
],
|
||||
package_dir={"": "src"},
|
||||
packages=setuptools.find_packages(where="src"),
|
||||
python_requires=">=3.6",
|
||||
)
|
||||
@@ -0,0 +1,26 @@
|
||||
# Running Tests
|
||||
|
||||
You must install the test-runner dependencies:
|
||||
```
|
||||
pip3 install -r tests/requirements.txt
|
||||
```
|
||||
|
||||
Then make the `seedsigner` python module visible/importable to the tests by installing it:
|
||||
```
|
||||
pip3 install -e .
|
||||
```
|
||||
|
||||
Run the whole test suite:
|
||||
```
|
||||
pytest
|
||||
```
|
||||
|
||||
Run a specific test file:
|
||||
```
|
||||
pytest tests/test_this_file.py
|
||||
```
|
||||
|
||||
Run a specific test:
|
||||
```
|
||||
pytest tests/test_this_file.py::test_this_specific_test
|
||||
```
|
||||
@@ -0,0 +1,2 @@
|
||||
pytest==6.2.4
|
||||
mock==4.0.3
|
||||
@@ -0,0 +1,42 @@
|
||||
import configparser
|
||||
import pytest
|
||||
from mock import MagicMock
|
||||
from seedsigner.controller import Controller
|
||||
|
||||
|
||||
|
||||
def test_singleton_init_fails():
|
||||
""" The Controller should not allow any code to instantiate it via Controller() """
|
||||
with pytest.raises(Exception):
|
||||
c = Controller()
|
||||
|
||||
def test_singleton_get_instance_without_configure_fails():
|
||||
""" Calling get_instance() without first calling configure_instance() should fail """
|
||||
with pytest.raises(Exception):
|
||||
c = Controller.get_instance()
|
||||
|
||||
def test_singleton_get_instance_preserves_state():
|
||||
""" Changes to the Controller singleton should be preserved across calls to get_instance() """
|
||||
settings = """
|
||||
[system]
|
||||
DEBUG = True
|
||||
DEFAULT_LANGUAGE = en
|
||||
|
||||
[display]
|
||||
BACKGROUND_COLOR = #000
|
||||
TEXT_COLOR = orange
|
||||
"""
|
||||
config = configparser.ConfigParser()
|
||||
config.read_string(settings)
|
||||
|
||||
# Initialize the instance and verify that it read the config settings
|
||||
Controller.configure_instance(config)
|
||||
controller = Controller.get_instance()
|
||||
assert controller.display_settings["text_color"] == "orange"
|
||||
|
||||
# Change a value in the instance...
|
||||
controller.display_settings["text_color"] = "purple"
|
||||
|
||||
# ...get a new copy of the instance and confirm change
|
||||
controller = Controller.get_instance()
|
||||
assert controller.display_settings["text_color"] == "purple"
|
||||
Reference in New Issue
Block a user