*** Wartungsfenster jeden ersten Mittwoch vormittag im Monat ***

Skip to content
Snippets Groups Projects
Commit e117cd59 authored by Moser, Maximilian's avatar Moser, Maximilian
Browse files

Add some tests for utility functions

parent f839cffc
No related branches found
No related tags found
1 merge request!1Update formatscaper according to identified requirements
...@@ -4,6 +4,10 @@ ...@@ -4,6 +4,10 @@
*.pickle *.pickle
*.sqlite *.sqlite
# don't ignore some YAML files though!
!.gitlab-ci.yml
!tests/**/*.yml
# logs # logs
sf.log sf.log
...@@ -16,3 +20,4 @@ formatscaper.egg-info ...@@ -16,3 +20,4 @@ formatscaper.egg-info
Pipfile Pipfile
Pipfile.lock Pipfile.lock
**/__pycache__ **/__pycache__
.coverage
...@@ -33,6 +33,12 @@ dev = [ ...@@ -33,6 +33,12 @@ dev = [
"flake8 >= 7.0", "flake8 >= 7.0",
"flake8-pyproject >= 1.2.3", "flake8-pyproject >= 1.2.3",
] ]
tests = [
"pytest >= 8.3",
"pytest-black >= 0.3",
"pytest-cov >= 5.0",
"pytest-isort >= 4.0",
]
[project.scripts] [project.scripts]
formatscaper = "formatscaper.cli:run_formatscaper_cli" formatscaper = "formatscaper.cli:run_formatscaper_cli"
...@@ -48,3 +54,11 @@ extend-ignore = ["E203", "E704"] ...@@ -48,3 +54,11 @@ extend-ignore = ["E203", "E704"]
[tool.isort] [tool.isort]
profile = "black" profile = "black"
[tool.pytest.ini_options]
addopts = '--black --isort --doctest-glob="*.rst" --doctest-modules --cov=formatscaper --cov-report=term-missing'
[tool.coverage.run]
omit = [
"formatscaper/cli/resultman.py"
]
"""Pytest configuration."""
- puid: x-fmt/111
name: Plain Text File
mime: text/plain
risk: 1
- puid: x-fmt/263
name: ZIP Format
mime: application/zip
risk: 2
- puid: UNKNOWN
name: null
mime: null
risk: 5
- puid: fmt/818
name: YAML
mime: null
risk: 1
- puid: fmt/938
name: Python Source Code File
mime: null
risk: 3
- puid: fmt/1149
name: Markdown
mime: text/markdown
risk: 1
- puid: fmt/43
name: JPEG File Interchange Format
mime: image/jpeg
risk: 1
- puid: fmt/615
name: Gimp Image File Format
mime: null
risk: 3
- puid: x-fmt/390
name: Exchangeable Image File Format (Compressed)
mime: image/jpeg
risk: 1
- puid: fmt/12
name: Portable Network Graphics
mime: image/png
risk: 1
- puid: fmt/1639
name: Adobe InDesign Document
mime: null
risk: 2
- puid: fmt/13
name: Portable Network Graphics
mime: image/png
risk: 2
- puid: fmt/11
name: Portable Network Graphics
mime: image/png
risk: 2
- puid: fmt/276
name: Acrobat PDF 1.7 - Portable Document Format
mime: application/pdf
risk: 1
- puid: fmt/215
name: Microsoft Powerpoint for Windows
mime: application/vnd.openxmlformats-officedocument.presentationml.presentation
risk: 2
- puid: fmt/412
name: Microsoft Word for Windows
mime: application/vnd.openxmlformats-officedocument.wordprocessingml.document
risk: 2
- puid: fmt/199
name: MPEG-4 Media File
mime: application/mp4
risk: 2
- puid: x-fmt/391
name: Exchangeable Image File Format (Compressed)
mime: image/jpeg
risk: 1
- puid: fmt/471
name: Hypertext Markup Language
mime: text/html
risk: 1
- puid: fmt/92
name: Scalable Vector Graphics
mime: image/svg+xml
risk: 1
- puid: fmt/4
name: Graphics Interchange Format
mime: image/gif
risk: 1
- puid: x-fmt/224
name: Cascading Style Sheet
mime: text/css
risk: 1
- puid: fmt/20
name: Acrobat PDF 1.6 - Portable Document Format
mime: application/pdf
risk: 1
- filename: hosts
uri: /etc/hosts
record: 1234-abcd
- filename: environment
uri: /etc/environment
record: 1234-abcd
- filename: FS Table
uri: /etc/fstab
record: 1234-abcd
- filename: original_name.pdf
uri: /home/mmoser/Documents/renamed.pdf
record: different-record
- filename: invenio-upload.zip
uri: /mnt/data/uploaded_data/12/34/56/data
record: qwer-5678
"""Testing the utility functions."""
import os
import tempfile
import yaml
from formatscaper.models import Format, RecordFile
from formatscaper.utils import load_formats, load_record_files, store_formats
def test_load_record_files_from_yaml():
"""Test loading of record files."""
record_files = load_record_files("tests/data/test_record_files.yml")
assert len(record_files) > 1
for record_file in record_files:
assert isinstance(record_file, RecordFile)
def test_load_formats():
"""Test loading of formats."""
formats = load_formats("tests/data/test_formats.yml")
assert len(formats) > 1
for format in formats.values():
assert isinstance(format, Format)
assert 0 <= format.risk <= 5
def test_store_formats():
"""Test storing of formats."""
formats = [
Format(puid="x-fmt/111", name="Plain Text File", mime="text/plain", risk=1),
Format(puid="fmt/615", name="Gimp Image File Format", mime=None, risk=3),
Format(puid="UNKNOWN", name=None, mime=None, risk=5),
]
try:
filename = tempfile.mktemp(suffix=".yml")
store_formats(formats, filename)
with open(filename, "r") as f:
result = yaml.safe_load(f)
assert len(result) == len(formats)
for format in formats:
assert format.as_dict() in result
finally:
os.remove(filename)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment