Skip to content

Commit

Permalink
Improve test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
mkitti committed Jul 15, 2023
1 parent 58328e0 commit 33c18bc
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 33 deletions.
63 changes: 33 additions & 30 deletions docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ SPHINXBUILD = sphinx-build
PAPER =
BUILDDIR = _build

# User-friendly check for sphinx-build
ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1)
$(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don\'t have Sphinx installed, grab it from http://sphinx-doc.org/)
endif
.PHONY: sphinx
sphinx:
# User-friendly check for sphinx-build
ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1)
$(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don\'t have Sphinx installed, grab it from http://sphinx-doc.org/)
endif

# Internal variables.
PAPEROPT_a4 = -D latex_paper_size=a4
Expand Down Expand Up @@ -54,44 +56,44 @@ clean:
rm -rf $(BUILDDIR)/*

.PHONY: html
html:
html: sphinx
$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
@echo
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."

.PHONY: dirhtml
dirhtml:
dirhtml: sphinx
$(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml
@echo
@echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml."

.PHONY: singlehtml
singlehtml:
singlehtml: sphinx
$(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml
@echo
@echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml."

.PHONY: pickle
pickle:
pickle: sphinx
$(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle
@echo
@echo "Build finished; now you can process the pickle files."

.PHONY: json
json:
json: sphinx
$(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json
@echo
@echo "Build finished; now you can process the JSON files."

.PHONY: htmlhelp
htmlhelp:
htmlhelp: sphinx
$(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp
@echo
@echo "Build finished; now you can run HTML Help Workshop with the" \
".hhp project file in $(BUILDDIR)/htmlhelp."

.PHONY: qthelp
qthelp:
qthelp: sphinx
$(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp
@echo
@echo "Build finished; now you can run "qcollectiongenerator" with the" \
Expand All @@ -101,7 +103,7 @@ qthelp:
@echo "# assistant -collectionFile $(BUILDDIR)/qthelp/zarr.qhc"

.PHONY: applehelp
applehelp:
applehelp: sphinx
$(SPHINXBUILD) -b applehelp $(ALLSPHINXOPTS) $(BUILDDIR)/applehelp
@echo
@echo "Build finished. The help book is in $(BUILDDIR)/applehelp."
Expand All @@ -110,7 +112,7 @@ applehelp:
"bundle."

.PHONY: devhelp
devhelp:
devhelp: sphinx
$(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp
@echo
@echo "Build finished."
Expand All @@ -120,111 +122,112 @@ devhelp:
@echo "# devhelp"

.PHONY: epub
epub:
epub: sphinx
$(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub
@echo
@echo "Build finished. The epub file is in $(BUILDDIR)/epub."

.PHONY: epub3
epub3:
epub3: sphinx
$(SPHINXBUILD) -b epub3 $(ALLSPHINXOPTS) $(BUILDDIR)/epub3
@echo
@echo "Build finished. The epub3 file is in $(BUILDDIR)/epub3."

.PHONY: latex
latex:
latex: sphinx
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
@echo
@echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex."
@echo "Run \`make' in that directory to run these through (pdf)latex" \
"(use \`make latexpdf' here to do that automatically)."

.PHONY: latexpdf
latexpdf:
latexpdf: sphinx
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
@echo "Running LaTeX files through pdflatex..."
$(MAKE) -C $(BUILDDIR)/latex all-pdf
@echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."

.PHONY: latexpdfja
latexpdfja:
latexpdfja: sphinx
$(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
@echo "Running LaTeX files through platex and dvipdfmx..."
$(MAKE) -C $(BUILDDIR)/latex all-pdf-ja
@echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."

.PHONY: text
text:
text: sphinx
$(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text
@echo
@echo "Build finished. The text files are in $(BUILDDIR)/text."

.PHONY: man
man:
man: sphinx
$(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man
@echo
@echo "Build finished. The manual pages are in $(BUILDDIR)/man."

.PHONY: texinfo
texinfo:
texinfo: sphinx
$(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
@echo
@echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo."
@echo "Run \`make' in that directory to run these through makeinfo" \
"(use \`make info' here to do that automatically)."

.PHONY: info
info:
info: sphinx
$(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
@echo "Running Texinfo files through makeinfo..."
make -C $(BUILDDIR)/texinfo info
@echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo."

.PHONY: gettext
gettext:
gettext: sphinx
$(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale
@echo
@echo "Build finished. The message catalogs are in $(BUILDDIR)/locale."

.PHONY: changes
changes:
changes: sphinx
$(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes
@echo
@echo "The overview file is in $(BUILDDIR)/changes."

.PHONY: linkcheck
linkcheck:
linkcheck: sphinx
$(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck
@echo
@echo "Link check complete; look for any errors in the above output " \
"or in $(BUILDDIR)/linkcheck/output.txt."

.PHONY: doctest
doctest:
doctest: sphinx
$(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest
@echo "Testing of doctests in the sources finished, look at the " \
"results in $(BUILDDIR)/doctest/output.txt."

.PHONY: coverage
coverage:
coverage: sphinx
$(SPHINXBUILD) -b coverage $(ALLSPHINXOPTS) $(BUILDDIR)/coverage
@echo "Testing of coverage in the sources finished, look at the " \
"results in $(BUILDDIR)/coverage/python.txt."

.PHONY: xml
xml:
xml: sphinx
$(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml
@echo
@echo "Build finished. The XML files are in $(BUILDDIR)/xml."

.PHONY: pseudoxml
pseudoxml:
pseudoxml: sphinx
$(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml
@echo
@echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml."

.PHONY: dummy
dummy:
dummy: sphinx
$(SPHINXBUILD) -b dummy $(ALLSPHINXOPTS) $(BUILDDIR)/dummy
@echo
@echo "Build finished. Dummy builder generates no files."

4 changes: 3 additions & 1 deletion docs/checksum32.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ Fletcher32
JenkinsLookup3
--------------

.. autoclass:: numcodecs.jenkins.JenkinsLookup3
.. autoclass:: JenkinsLookup3

.. autoattribute:: codec_id
.. autoattribute:: initval
.. autoattribute:: prefix
.. automethod:: encode
.. automethod:: decode
2 changes: 1 addition & 1 deletion numcodecs/checksum32.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def decode(self, buf, out=None):
f" match the expected checksum ({found}).\n"
"This could be a sign that the data has been corrupted."
)
if out:
if out is not None:
out.view("uint8")[:] = b[:-4]
return out
return memoryview(b[:-4])
2 changes: 1 addition & 1 deletion numcodecs/fletcher32.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class Fletcher32(Codec):
f" match the expected checksum ({found}).\n"
"This could be a sign that the data has been corrupted."
)
if out:
if out is not None:
out.view("uint8")[:] = b[:-4]
return out
return memoryview(b[:-4])
7 changes: 7 additions & 0 deletions numcodecs/tests/test_fletcher32.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,10 @@ def test_known():
1911, -2427, 1897, -2412, 2440, 873, -621, -829, 551, -2118,
]
assert outarr.tolist() == expected


def test_out():
data = np.frombuffer(bytearray(b"Hello World"), dtype="uint8")
f = Fletcher32()
result = f.encode(data)
f.decode(result, out=data)
28 changes: 28 additions & 0 deletions numcodecs/tests/test_jenkins.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import numpy as np
import pytest

from numcodecs.jenkins import jenkins_lookup3
from numcodecs.checksum32 import JenkinsLookup3
Expand Down Expand Up @@ -119,3 +120,30 @@ def test_jenkins_lookup3_codec():
result = j.encode(chunk_index[:-4])
j.decode(result)
assert result == chunk_index

@pytest.mark.parametrize(
"dtype",
["uint8", "int32", "float32"]
)
def test_with_data(dtype):
data = np.arange(100, dtype=dtype)
j = JenkinsLookup3()
arr = np.frombuffer(j.decode(j.encode(data)), dtype=dtype)
assert (arr == data).all()


def test_error():
data = np.arange(100)
j = JenkinsLookup3()
enc = j.encode(data)
enc2 = bytearray(enc)
enc2[0] += 1
with pytest.raises(RuntimeError) as e:
j.decode(enc2)
assert "Bob Jenkin's lookup3 checksum" in str(e.value)

def test_out():
data = np.frombuffer(bytearray(b"Hello World"), dtype="uint8")
j = JenkinsLookup3()
result = j.encode(data)
j.decode(result, out=data)

0 comments on commit 33c18bc

Please sign in to comment.