Fixture function to remove all glossaries from the server matching the given predicate. Can be used, for example, to remove all glossaries with a matching name. Usage example: def test_example(cleanup_matching_glossaries): ... cleanup_matching_glossa
(deepl_client)
| 207 | |
| 208 | @pytest.fixture |
| 209 | def cleanup_matching_glossaries(deepl_client): |
| 210 | """ |
| 211 | Fixture function to remove all glossaries from the server matching the |
| 212 | given predicate. Can be used, for example, to remove all glossaries with a |
| 213 | matching name. |
| 214 | |
| 215 | Usage example: |
| 216 | def test_example(cleanup_matching_glossaries): |
| 217 | ... |
| 218 | cleanup_matching_glossaries( |
| 219 | lambda glossary: glossary.name.startswith("test ") |
| 220 | ) |
| 221 | """ |
| 222 | |
| 223 | def do_cleanup(predicate: Callable[[deepl.GlossaryInfo], bool]): |
| 224 | glossaries = deepl_client.list_multilingual_glossaries() |
| 225 | for glossary in glossaries: |
| 226 | if predicate(glossary): |
| 227 | try: |
| 228 | deepl_client.delete_multilingual_glossary(glossary) |
| 229 | except deepl.DeepLException: |
| 230 | pass |
| 231 | |
| 232 | return do_cleanup |
| 233 | |
| 234 | |
| 235 | class ManagedGlossary: |
no outgoing calls
no test coverage detected