Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions in2lambda/json_convert/json_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
def _zip_sorted_folder(folder_path, zip_path):
"""Zips the contents of a folder, preserving the directory structure.

Lambda Feedback imports questions in archive order, so the files are sorted.

Args:
folder_path: The path to the folder to zip.
zip_path: The path where the zip file will be created.
Expand Down Expand Up @@ -187,6 +189,7 @@ def converter(SetQuestions: Set, output_dir: str) -> None:
# Output file
filename = (
"question_"
# Alphabetical order is question order for up to 1000 questions
+ str(i).zfill(3)
+ "_"
+ re.sub(r"[^\w\-_.]", "_", output["title"].strip())
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/exports/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ answers, worked solutions, structured tutorials and the chatbot.

| key | meaning |
|---|---|
| `orderNumber` | position in the set, from 0; matches the filename |
| `orderNumber` | position in the set, from 0; matches the filename. The importer currently follows archive order, so the two must agree |
| `title` | shown to students |
| `skill` | difficulty (exports use 1/3 and 2/3) |
| `guidance` | a sentence to students about the question's purpose |
Expand Down
11 changes: 11 additions & 0 deletions tests/test_export_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"""

import json
import zipfile
from pathlib import Path

from in2lambda.api.part import Part
Expand Down Expand Up @@ -93,3 +94,13 @@ def test_each_response_type_writes_the_settings_of_a_real_export() -> None:
evaluation_function=""
)
assert set(written._config() or {}) == set(response["config"] or {})


def test_the_zip_lists_questions_in_order_number_order(tmp_path) -> None:
titles = ["Zeta", "Alpha", "Mu"]
Set(questions=[Question(title=t) for t in titles]).to_json(str(tmp_path))

with zipfile.ZipFile(tmp_path / "set.zip") as zf:
names = [n for n in zf.namelist() if n.startswith("question_")]
orders = [json.loads(zf.read(n))["orderNumber"] for n in names]
assert orders == list(range(len(titles)))
Loading