hypothesis-protobuf
hypothesis-protobuf copied to clipboard
modules_to_strategies hangs when protobuf files import from same package
Problem
The while loop in the modules_to_strategies
function does not terminate when using a package with multiple .proto
files with inter-package dependencies.
Why?
The loop attempts to load each module into the environment. To load a module it requires all of the module's dependencies to have loaded:
https://github.com/hchasestevens/hypothesis-protobuf/blob/f922a996880e6dc4a0e17cccf75a29e47bf9aa0a/hypothesis_protobuf/module_conversion.py#L200
However, this condition is too strict. It actually check's if all of the packages of the dependencies have loaded, rather than just the depended upon modules.
If there are two modules in the same package, where one imports and hence depends on the other, then this condition never becomes true (as the package never loads) and the while loop never terminates.
Minimal test case
Test case directory structure:
hypothesis-pb-ex
├── compile.sh
├── ex
│ └── protos
│ ├── base.proto
│ └── ext.proto
└── test.py
compile.sh
is a bash script to generate Python modules from the protobuf files:
#!/bin/bash
protoc --proto_path . --python_out=. ex/protos/*.proto
base.proto
is a simple message:
syntax = "proto3";
package ex.protos;
message Base {
bool field = 1;
}
ext.proto
is a message with a Base
field:
syntax = "proto3";
package ex.protos;
import "ex/protos/base.proto";
message Ext {
Base base = 1;
}
test.py
is a Python script to import the modules and run modules_to_strategies
:
from hypothesis_protobuf import modules_to_strategies
from ex.protos import ext_pb2
print('start', flush=True)
modules_to_strategies(ext_pb2)
print('end', flush=True)
To run the test case first compile the protocol buffers and then run the Python script:
$ chmod +x compile.sh
$ ./compile.sh
$ python test.py
Any update on this issue? Looks like this package isn’t maintained anymore?