apluslms / a-plus-rst-tools

Tools to publish RST course content for mooc-grader and a-plus. Should be cloned as a course submodule.
MIT License
5 stars 24 forks source link

key_without_language() reimplemented with regexp #136

Open atilante opened 2 years ago

atilante commented 2 years ago

Description

What?

This pull request contains several related modifications to A+ RST Tools issue #134. https://github.com/apluslms/a-plus-rst-tools/issues/134

  1. In lib/toc_languages.py, functions key_without_language() and join_keys() were refactored into methods in the class IndexJoiner. This is more consistent, as there are other "join"-named methods in IndexJoiner.

  2. Method key_without_language() in lib/toclanguages.py had a bug: the function could only strip language ids of form "id" and "id-", not "_id" or "id". The bug was discovered with course the CS-A1141 Data Structures and Algorithms Y. The function is now reimplemented with a more flexible regular expression.

  3. Method join_keys in lib/toc_languages.py now prints a warning message into log. The message describes the location of mismatching keys in the documentation tree, and mismatching keys with their language identifiers. Example:

    Mismatching keys at modules.1.2.3: Language: en Key: sorting_en_something Language: fi Key: sorting_fi_different

This should help the course material author locate the error. Moreover, as the method now logs an error message instead of raising a SphinxError, the compilation process can show log messages of all mismatching keys at one compilation run, thus increasing productivity.

  1. Unit test file tests/test_toc_languages.py tests the aforementioned modified functions. The unit tests allow the A-plus RST tools developer to: (i) easily test the functions of the software without needing to run a Sphinx compilation of a test material, which can take minutes; (ii) document how the functions should respond to certain inputs.

Why?

A+ RST Tools could not produce a helpful error message when there was something inconsistent with keys on multilingual courses.

How?

Described above.

Fixes #134

Testing

Python unit tests are introduced to A+ RST Tools in this pull request. There is the new directory "tests".

What type of test did you run?

[ADD A DESCRIPTION ABOUT WHAT YOU TESTED MANUALLY]

Did you test the changes in

Think of what is affected by these changes and could become broken

Translation

Programming style

Have you updated the README or other relevant documentation?

Is it Done?

Clean up your git commit history before submitting the pull request!