Skip to content

Commit cb469ce

Browse files
authored
Testing (#3)
* Write tests for openning a file * Update open to warn if the file is incomplete * Now closing the file if there is an error opening it * Add a test to open valid files * Shrink test file * Write tests for the header * Write tests for get sweep n * Write tests for get_all_sweeps and dunder methods * Write a test for files with no sweeps * Write tests for the sweeps * Write visualization tests * Reformat the files * Add version file * Getting things ready for publishing * Create github workflow * Fix syntax error * Fix another error * Add pytest install... * Testing the CI/CD * Confirmed that CI/CD will fail if a test fails * Update documentation
1 parent 9746e69 commit cb469ce

21 files changed

Lines changed: 411 additions & 22 deletions

.github/workflows/unittest.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Testing
2+
on:
3+
push:
4+
branches: [ "master" ]
5+
pull_request:
6+
branches: [ "master" ]
7+
permissions:
8+
contents: read
9+
jobs:
10+
tests:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v3
14+
- name: Python 3.10 setup
15+
uses: actions/setup-python@v3
16+
with:
17+
python-version: "3.10"
18+
- name: Install dependencies
19+
run: |
20+
python -m pip install --upgrade pip
21+
pip install .
22+
pip install pytest
23+
24+
- name: Unit testing
25+
run: |
26+
pytest -v

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
.idea/
2-
*.shr
32
build/
43
py_shr_parser.egg-info
54
__pycache__/

Documentation/appendix.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22
Appendix
33
========
44

5+
Related Software
6+
================
7+
* shr-parser_: A Rust library for parsing SHR files.
8+
* shr-parser-py_: Another Python package for parsing SHR files written in Rust. This project is no longer
9+
maintained at the time of writing.
10+
11+
.. _shr-parser: https://github.com/Xerrion/shr_parser
12+
.. _shr-parser-py: https://pypi.org/project/shr-parser/
13+
514
License
615
=======
716
Copyright (c) 2025, WiSELab-CMU

Documentation/pyshrparser.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ This installs a package that can be used from Python (``import shr_parser``).
3434
To install for all users on the system, administrator
3535
rights (root) may be required.
3636

37-
From PyPI (Not published yet. This doesn't work yet)
37+
From PyPI
3838
----------------------------------------------------
3939
pyshrparser can be installed from PyPI::
4040

41-
pip install pyshrparser
42-
python3 -m pip install pyshrparser
41+
pip install py-shr-parser
42+
python3 -m pip install py-shr-parser
4343

4444
Developers also may be interested to get the source archive, because it
4545
contains examples, tests and this documentation.

README.rst

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,25 @@ Documentation
1515
-------------
1616
For API documentation, usage and examples, see the files in the "Documentation" directory.
1717
The ".rst" files can be read in any text editor or being converted to HTML or PDF
18-
using Sphinx.
18+
using Sphinx_. Examples can be found in the documentation and tests.
1919

20-
Examples
21-
--------
22-
Examples do not exist yet...
20+
.. _Sphinx: https://www.sphinx-doc.org/en/master/
2321

2422
Installation
2523
------------
26-
Eventually will be published on PyPl. Currently download the repo and run
2724

2825
.. code-block:: none
2926
30-
pip install <path to root of this repo>
27+
pip install py-shr-parser
28+
29+
Basic Example
30+
-------------
31+
This shows how to open an SHR file and load all the sweep data.
32+
33+
.. code-block:: python
34+
35+
from shr_parser import ShrFileParser
36+
with ShrFileParser("foo.shr") as parser:
37+
sweeps = parser.get_all_sweeps()
38+
39+
The above example is very basic. For more advanced examples, please refer to the Documentation.

pyproject.toml

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,36 @@ requires = ["setuptools>=61.0"]
33
build-backend = "setuptools.build_meta"
44

55
[tool.setuptools.packages.find]
6-
where = ["."]
6+
where = ["src"]
77

88
[project]
99
name = "py-shr-parser"
10-
version = "0.0.0"
10+
version = "1.0.0"
1111
authors = [
1212
{ name = "Tom Schmitz", email="tschmitz@andrew.cmu.edu" },
1313
]
1414
description = "Python library for parsing Signal Hound SHR files"
1515
requires-python = ">=3.8"
1616
classifiers = [
17+
"Development Status :: 5 - Production/Stable",
1718
"Programming Language :: Python :: 3",
18-
"Operating System :: OS Independent"
19+
"Operating System :: OS Independent",
1920
]
2021
dependencies = [
2122
"numpy",
2223
"matplotlib",
2324
]
25+
license = "BSD-3-Clause"
26+
keywords = ["SHR", "Signal Hound",]
27+
readme = "README.rst"
28+
29+
[project.urls]
30+
Homepage = "https://github.com/WiseLabCMU/py-shr-parser"
31+
"Bug Tracker" = "https://github.com/WiseLabCMU/py-shr-parser/issues"
32+
33+
[tool.pytest.ini_options]
34+
minversion = "6.0"
35+
addopts = "-ra -q"
36+
testpaths = [
37+
"tests",
38+
]
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from .shr_parser import ShrSweep, ShrFileParser
22
from .enumerations import ShrScale, ShrWindow, ShrDecimationDetector, ShrVideoDetector, ShrVideoUnits, ShrDecimationType, ShrChannelizerOutputUnits
3-
from .exceptions import ShrFileParserException, FileNotOpenError
3+
from .exceptions import ShrFileParserException, FileNotOpenError, ShrFileParserWarning
44
from .metadata import ShrSweepHeader, ShrFileHeader
5+
from .version import __version__
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,8 @@ class FileNotOpenError(ShrFileParserException):
88

99
def __init__(self):
1010
super().__init__("File not open")
11+
12+
13+
class ShrFileParserWarning(RuntimeWarning):
14+
"""Warning indicating that further parsing may result in an error"""
15+
pass

0 commit comments

Comments
 (0)