Skip to content
Snippets Groups Projects
Commit 5b66f383 authored by Eliott Sammier's avatar Eliott Sammier
Browse files

Add basic tests counting Modules, SousParties and Activites

parent 1e270a00
Branches
No related tags found
1 merge request!1Main
...@@ -55,12 +55,18 @@ setup ...@@ -55,12 +55,18 @@ setup
Initialize Python environment required by extractors Initialize Python environment required by extractors
setup-debug setup-debug
(Re)create .env file used by the Python debugger launch config (Re)create .env file used by the Python debugger launch config
extract-rdf extract
Run the extractor to generate RDF from text sources Run the extract stage, to generate RDF from text sources
extract-mp3 [-y|--yes-overwrite] transform
Extract audio streams from all Flash SWF files Run the transform stage, to complete and clean-up the RDF data
export
Run the export stage, to generate Macao-Hugo content pages
convert convert
Run the full conversion process (extract -> transform -> export) Run the full conversion process (extract -> transform -> export)
test
Run simple tests on the extracted RDF data
extract-mp3 [-y|--yes-overwrite]
Extract audio streams from all Flash SWF files
help help
Print this help and exit Print this help and exit
EOF EOF
...@@ -264,6 +270,10 @@ export) ...@@ -264,6 +270,10 @@ export)
activate_venv activate_venv
python "$SCRIPTS_DIR/src/export.py" python "$SCRIPTS_DIR/src/export.py"
;; ;;
test)
activate_venv
python "$SCRIPTS_DIR/src/test.py"
;;
extract-mp3) extract-mp3)
for audio_file in "$SOURCES_DIR/contenu/media/"*.swf; do for audio_file in "$SOURCES_DIR/contenu/media/"*.swf; do
"$SCRIPTS_DIR/extract_mp3.sh" "$@" --output-dir "$RESULTS_DIR/audio" "$audio_file" "$SCRIPTS_DIR/extract_mp3.sh" "$@" --output-dir "$RESULTS_DIR/audio" "$audio_file"
......
...@@ -35,6 +35,14 @@ ...@@ -35,6 +35,14 @@
"program": "src/main.py", "program": "src/main.py",
"console": "integratedTerminal", "console": "integratedTerminal",
"envFile": "${workspaceFolder}/.env" "envFile": "${workspaceFolder}/.env"
},
{
"name": "Python: test",
"type": "debugpy",
"request": "launch",
"program": "src/test.py",
"console": "integratedTerminal",
"envFile": "${workspaceFolder}/.env"
} }
] ]
} }
\ No newline at end of file
...@@ -9,5 +9,15 @@ ...@@ -9,5 +9,15 @@
}, },
"editor.formatOnSave": true, "editor.formatOnSave": true,
"python.analysis.autoImportCompletions": true, "python.analysis.autoImportCompletions": true,
"python.analysis.typeCheckingMode": "basic" "python.analysis.typeCheckingMode": "basic",
"python.envFile": "${workspaceFolder}/.env",
"python.testing.unittestArgs": [
"-v",
"-s",
"./src",
"-p",
"test*.py"
],
"python.testing.pytestEnabled": false,
"python.testing.unittestEnabled": true
} }
\ No newline at end of file
import unittest
from rdflib import Graph
import extract
import transform
from common import *
class TestObjectCount(unittest.TestCase):
def __init__(self, methodName): # pyright: ignore[reportMissingParameterType]
super().__init__()
# Run extraction
extract.main()
transform.main()
# Load graph
self.graph = Graph()
self.graph.bind("", NS)
self.graph.parse(RDF_FULL_FILE)
def runTest(self):
# Modules
self.assertCount(
"""SELECT DISTINCT ?mod WHERE {
?mod a :Module .
?mod :id ?id .
?mod :index ?index .
?mod :titre ?titre .
MINUS { ?mod a :SousPartie }
}""",
(9, 6, 9 + 6),
)
# SousParties
self.assertCount(
"""SELECT DISTINCT ?subj WHERE {
?subj a :SousPartie .
?subj :id ?id .
?subj :index ?index .
?subj :titre ?titre .
}""",
(18, 14, 18 + 14),
)
# Activités
self.assertCount(
"""SELECT DISTINCT ?subj WHERE {
?subj a :Activite .
?subj :id ?id .
?subj :index ?index .
?subj :titre ?titre .
}""",
(132, 86, 132 + 86),
)
def assertCount(
self, query: str, expected_tuple: tuple[int | None, int | None, int | None]
):
"""Checks that the `query` produces the expected number of results.
The `expected_tuple` contains 3 values, for the macao_12 graph,
macao_3 graph, and both combined. A `None` value in the tuple ignores this check.
"""
res = self.graph.query(query)
count = len(res)
versions = ("macao_12", "macao_3", "full")
try:
expected = expected_tuple[versions.index(MACAO_VERSION)]
except ValueError:
self.fail(f"Unknown version '{Context.version}'")
if expected is not None:
self.assertEqual(count, expected)
# else skip test
if __name__ == "__main__":
unittest.main()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment