Merged
Conversation
This is needed to fix the `aggregate/convert_to_json` crash due to error `Unable to parse classname: "unittest.loader.ModuleImportFailure"` that currently occurs when running ./ci-python on Python 2. When `unittest` automatically imports modules during test discovery and some file cannot be imported (e.g. due to a syntax error), the error is reported under the classname `unittest.loader.ModuleImportFailure`, which obviously doesn't match the `/\.Test([^.]*)$/` pattern expected for normal tests. But in that case we just want to skip prepending the classname and continue, not crash - this is not a fatal error.
... to avoid inaccurracies
See previous commit e92fb33
Avoid unnecessarily compiling both `spec` and `specwrite` suites twice, each time only to run tests from one suite. This means that the compilation should be faster, the compile errors (mostly in generated Java sources) won't be duplicated in the console output, and our CI infrastructure will no longer report them (also) in the wrong suite.
The `assertRaisesRegexp` method of `unittest.TestCase` was removed in Python 3.12, see kaitai-io/kaitai_struct#1104 Since 8420002...b1452a3 we have a better way of checking the error message that doesn't use regular expressions (and is well compatible across Python versions), so let's use it.
This is way more flexible than the `-w, --read-write` option, and arguably makes more sense. For example, you can now pass `-t python -t python-write` at once, which wasn't possible before. It also fixes `-t all` to really mean *all* target languages (including `java-write` and `python-write`), not just the read-only "languages".
Previously, the `_check_{inst}()` methods were invoked before the
corresponding parse instances, leading to attempts to access undefined
`_m_*` attributes. As a result, some tests that should have passed were
failing.
The fix is to call all `_check*()` methods only after dumping the entire
object, when all instances have been already invoked.
See d0da8e5 Note: it was tricky to reproduce the problem that this commit fixes. According to the Java documentation [for the `java.lang.Class.getDeclaredMethods()` method](https://docs.oracle.com/javase/8/docs/api/java/lang/Class.html#getDeclaredMethods--): > The elements in the returned array are not sorted and are not in any > particular order. And indeed, when I compared the values of the `methodName` variable from two consecutive runs of the entire test suite, they were in a slightly different order. But not different enough to cause any test failures. In order to reliably reproduce the problem, it proved effective to explicitly shuffle the array of methods, for example as follows: ```diff diff --git i/spec/java/src/io/kaitai/struct/specwrite/CommonSpec.java w/spec/java/src/io/kaitai/struct/specwrite/CommonSpec.java index 0169d82..16916052 100644 --- i/spec/java/src/io/kaitai/struct/specwrite/CommonSpec.java +++ w/spec/java/src/io/kaitai/struct/specwrite/CommonSpec.java @@ -7,4 +7,6 @@ import java.nio.file.Files; import java.nio.file.Paths; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; import java.util.HashMap; import java.util.IdentityHashMap; @@ -108,5 +110,8 @@ public abstract class CommonSpec extends io.kaitai.struct.spec.CommonSpec { } parentStructs.put(struct, currentPath); - for (final Method m : struct.getClass().getDeclaredMethods()) { + Method[] methods = struct.getClass().getDeclaredMethods(); + List<Method> methodsAsList = Arrays.asList(methods); + Collections.shuffle(methodsAsList); + for (final Method m : methods) { if (!Modifier.isPublic(m.getModifiers())) continue; if (Modifier.isStatic(m.getModifiers())) continue; // ignore static methods, i.e. "fromFile" ```
See b4b2ccc Of course, `java-write` and `python-write` are not real languages, so their generated test specs should go into the `spec/{java,python}` folders (not `spec/{java,python}-write`).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.