Skip to content

Commit 53f30b4

Browse files
committed
init repo
0 parents  commit 53f30b4

21 files changed

+1127
-0
lines changed

.gitattributes

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Set the default behavior, in case people don't have core.autocrlf set.
2+
* text=auto
3+
4+
# Explicitly declare text files you want to always be normalized and converted
5+
# to native line endings on checkout.
6+
*.py text eol=lf
7+
*.rst text eol=lf
8+
.gitattributes text eol=lf
9+
.gitignore text eol=lf
10+
*.yaml text eol=lf
11+
*.yml text eol=lf
12+
LICENSE text eol=lf
13+
*.toml text eol=lf
14+
*.txt text eol=lf

.gitignore

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
__pycache__/
2+
*.py[cod]
3+
*$py.class
4+
5+
# C extensions
6+
*.so
7+
8+
# Distribution / packaging
9+
.Python
10+
build*/
11+
bundles/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
pip-wheel-metadata/
24+
share/python-wheels/
25+
*.egg-info/
26+
.installed.cfg
27+
*.egg
28+
MANIFEST
29+
30+
# PyInstaller
31+
# Usually these files are written by a python script from a template
32+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
33+
*.manifest
34+
*.spec
35+
36+
# Installer logs
37+
pip-log.txt
38+
pip-delete-this-directory.txt
39+
40+
# Unit test / coverage reports
41+
htmlcov/
42+
.tox/
43+
.nox/
44+
.coverage
45+
.coverage.*
46+
.cache
47+
nosetests.xml
48+
coverage.xml
49+
*.cover
50+
*.py,cover
51+
.hypothesis/
52+
.pytest_cache/
53+
54+
# Translations
55+
*.mo
56+
*.pot
57+
58+
# Django stuff:
59+
*.log
60+
local_settings.py
61+
db.sqlite3
62+
db.sqlite3-journal
63+
64+
# Flask stuff:
65+
instance/
66+
.webassets-cache
67+
68+
# Scrapy stuff:
69+
.scrapy
70+
71+
# Sphinx documentation
72+
docs/_build/
73+
docs/social_cards_cache/
74+
75+
# PyBuilder
76+
target/
77+
78+
# Jupyter Notebook
79+
.ipynb_checkpoints
80+
81+
# IPython
82+
profile_default/
83+
ipython_config.py
84+
85+
# pyenv
86+
.python-version
87+
88+
# pipenv
89+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
90+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
91+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
92+
# install all needed dependencies.
93+
#Pipfile.lock
94+
95+
# celery beat schedule file
96+
celerybeat-schedule
97+
98+
# SageMath parsed files
99+
*.sage.py
100+
101+
# Environments
102+
.env
103+
.venv
104+
env/
105+
venv/
106+
ENV/
107+
env.bak/
108+
venv.bak/
109+
110+
# Spyder project settings
111+
.spyderproject
112+
.spyproject
113+
114+
# Rope project settings
115+
.ropeproject
116+
117+
# mkdocs documentation
118+
/site
119+
120+
# mypy
121+
.mypy_cache/
122+
.dmypy.json
123+
dmypy.json
124+
125+
# Pyre type checker
126+
.pyre/
127+
128+
# VS Code folder
129+
.vscode

.pre-commit-config.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# See https://pre-commit.com for more information
2+
# See https://pre-commit.com/hooks.html for more hooks
3+
repos:
4+
- repo: https://github.com/pre-commit/pre-commit-hooks
5+
rev: v4.6.0
6+
hooks:
7+
- id: trailing-whitespace
8+
- id: end-of-file-fixer
9+
- id: check-yaml
10+
- id: check-toml
11+
- id: requirements-txt-fixer
12+
- id: mixed-line-ending
13+
args: ["--fix=lf"]
14+
- id: check-added-large-files
15+
- repo: https://github.com/pre-commit/mirrors-mypy
16+
rev: v1.11.0
17+
hooks:
18+
- id: mypy
19+
- repo: https://github.com/astral-sh/ruff-pre-commit
20+
rev: v0.5.2
21+
hooks:
22+
# Run the python linter.
23+
- id: ruff
24+
args: [ --fix ]
25+
# Run the python formatter.
26+
- id: ruff-format

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2024 Brendan Doherty
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
Read The Docs
3+
=============
4+
5+
Documentation for this library is hosted at https://circuitpython-nrf24l01.rtfd.io/
6+
7+
About this Library
8+
==================
9+
10+
This is a library of mock data structures to be used in soft-testing Circuitpython code.

circuitpython_mocks/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from pathlib import Path
2+
import pytest
3+
4+
5+
@pytest.fixture(autouse=True)
6+
def monkey_patch_sys_paths(monkeypatch: pytest.MonkeyPatch):
7+
root_pkg = Path(__file__).parent
8+
monkeypatch.syspath_prepend(str(root_pkg))

circuitpython_mocks/_mixins.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
from typing import Self
2+
from collections import deque
3+
from typing import TYPE_CHECKING
4+
5+
if TYPE_CHECKING:
6+
from circuitpython_mocks.busio.operations import Read, Write, Transfer
7+
from circuitpython_mocks.digitalio.operations import SetState, GetState
8+
9+
10+
class ContextManaged:
11+
"""An object that automatically deinitializes hardware with a context manager."""
12+
13+
def __enter__(self) -> Self:
14+
return self
15+
16+
def __exit__(self, exc_type, exc_value, traceback):
17+
self.deinit()
18+
19+
def deinit(self):
20+
"""Free any hardware used by the object."""
21+
return
22+
23+
24+
class Lockable(ContextManaged):
25+
"""An object that must be locked to prevent collisions on a microcontroller resource."""
26+
27+
_locked = False
28+
29+
def try_lock(self):
30+
"""Attempt to grab the lock. Return True on success, False if the lock is already taken."""
31+
if self._locked:
32+
return False
33+
self._locked = True
34+
return True
35+
36+
def unlock(self):
37+
"""Release the lock so others may use the resource."""
38+
if self._locked:
39+
self._locked = False
40+
41+
42+
class Expecting:
43+
def __init__(self, **kwargs) -> None:
44+
self.expectations: deque[Read | Write | Transfer | SetState | GetState] = (
45+
deque()
46+
)
47+
super().__init__(**kwargs)
48+
49+
def done(self):
50+
assert not self.expectations, (
51+
"Some expectations were unused:\n "
52+
+ "\n ".join([repr(x) for x in self.expectations])
53+
)
54+
55+
def __del__(self):
56+
self.done()

circuitpython_mocks/board.py

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
"""Mock pins"""
2+
3+
class Pin:
4+
pass
5+
6+
7+
D0 = Pin()
8+
D1 = Pin()
9+
D2 = Pin()
10+
D3 = Pin()
11+
D4 = Pin()
12+
D5 = Pin()
13+
D6 = Pin()
14+
D7 = Pin()
15+
D8 = Pin()
16+
D9 = Pin()
17+
D10 = Pin()
18+
D11 = Pin()
19+
D12 = Pin()
20+
D13 = Pin()
21+
D14 = Pin()
22+
D15 = Pin()
23+
D16 = Pin()
24+
D17 = Pin()
25+
D18 = Pin()
26+
D19 = Pin()
27+
D20 = Pin()
28+
D21 = Pin()
29+
D22 = Pin()
30+
D23 = Pin()
31+
D24 = Pin()
32+
D25 = Pin()
33+
D26 = Pin()
34+
D27 = Pin()
35+
D28 = Pin()
36+
D29 = Pin()
37+
D30 = Pin()
38+
D31 = Pin()
39+
D32 = Pin()
40+
D33 = Pin()
41+
D34 = Pin()
42+
D35 = Pin()
43+
D36 = Pin()
44+
D37 = Pin()
45+
D38 = Pin()
46+
D39 = Pin()
47+
D40 = Pin()
48+
D41 = Pin()
49+
D42 = Pin()
50+
D43 = Pin()
51+
D44 = Pin()
52+
D45 = Pin()
53+
D46 = Pin()
54+
D47 = Pin()
55+
D48 = Pin()
56+
D49 = Pin()
57+
D50 = Pin()
58+
D51 = Pin()
59+
D52 = Pin()
60+
D53 = Pin()
61+
D54 = Pin()
62+
D55 = Pin()
63+
D56 = Pin()
64+
D57 = Pin()
65+
D58 = Pin()
66+
D59 = Pin()
67+
D60 = Pin()
68+
D61 = Pin()
69+
D62 = Pin()
70+
D63 = Pin()
71+
D64 = Pin()
72+
D65 = Pin()
73+
D66 = Pin()
74+
D67 = Pin()
75+
D68 = Pin()
76+
D69 = Pin()
77+
D70 = Pin()
78+
D71 = Pin()
79+
D72 = Pin()
80+
D73 = Pin()
81+
D74 = Pin()
82+
D75 = Pin()
83+
D76 = Pin()
84+
D77 = Pin()
85+
D78 = Pin()
86+
D79 = Pin()
87+
D80 = Pin()
88+
D81 = Pin()
89+
D82 = Pin()
90+
D83 = Pin()
91+
D84 = Pin()
92+
D85 = Pin()
93+
D86 = Pin()
94+
D87 = Pin()
95+
D88 = Pin()
96+
D89 = Pin()
97+
D90 = Pin()
98+
D91 = Pin()
99+
D92 = Pin()
100+
D93 = Pin()
101+
D94 = Pin()
102+
D95 = Pin()
103+
D96 = Pin()
104+
D97 = Pin()
105+
D98 = Pin()
106+
D99 = Pin()
107+
108+
SDA = Pin()
109+
SCL = Pin()
110+
111+
CE1 = Pin()
112+
CE0 = Pin()
113+
MISO = Pin()
114+
MOSI = Pin()
115+
SCLK = Pin()
116+
SCK = Pin()
117+
118+
TXD = Pin()
119+
RXD = Pin()
120+
121+
# create alias for most of the examples
122+
TX = Pin()
123+
RX = Pin()
124+
125+
MISO_1 = Pin()
126+
MOSI_1 = Pin()
127+
SCLK_1 = Pin()
128+
SCK_1 = Pin()

0 commit comments

Comments
 (0)