You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a hypothesis stateful test including some posix operations like create/open/mkdir/unlink/read/write etc. I want use this the stateful test to generate a complex directory structure including lots of directories and files, used for other tests.
I try to set max_examples to 1 and stateful_step_count to 10000,but it will finish in a few steps.
Is there a way to make sure I can run enough steps to generate massive data?
This is some of the test code:
import os
from string import ascii_lowercase
from hypothesis import Verbosity, assume, strategies as st
from hypothesis.stateful import rule, precondition, RuleBasedStateMachine, Bundle, initialize, consumes
from hypothesis import seed, settings
@settings(verbosity=Verbosity.debug,
max_examples=10,
stateful_step_count=10)
class PosixMachine(RuleBasedStateMachine):
ROOT_DIR1='/tmp/fsrand'
ROOT_DIR2='/mnt/jfs/fsrand'
Files = Bundle('files')
Folders = Bundle('folders')
@initialize(target=Folders)
def init_folders(self):
return ''
def __init__(self):
super(PosixMachine, self).__init__()
@rule(target=Files, parent = Folders, file_name = st.text(alphabet=ascii_lowercase, min_size=254))
def create_file(self, parent, file_name):
result1 = self.do_create_file(self.ROOT_DIR1, parent, file_name)
result2 = self.do_create_file(self.ROOT_DIR2, parent, file_name)
assert result1 == result2
if isinstance(result1, tuple):
return os.path.join(parent, file_name)
else: # create file failed, so we should not put the file in the target
print('create file failed')
return multiple()
def do_create_file(self, root_dir, parent, file_name):
relpath = os.path.join(parent, file_name)
abspath = os.path.join(root_dir, relpath)
try:
with open(abspath, 'x') as file:
file.write('abc')
except Exception as e :
return str(e)
return os.stat(abspath)
@rule(target=Files, file = Files)
def unlink(self, file):
result1 = self.do_unlink(self.ROOT_DIR1, file)
result2 = self.do_unlink(self.ROOT_DIR2, file)
assert result1 == result2
if isinstance(result1, tuple):
return multiple()
else:
return file
def do_unlink(self, root_dir, file):
abspath = os.path.join(root_dir, file)
try:
os.unlink(abspath)
except Exception as e:
return str(e)
return ()
if name == 'main':
juicefs_machine = PosixMachine.TestCase()
juicefs_machine.runTest()
The text was updated successfully, but these errors were encountered:
zhoucheng361
changed the title
how to generate mass data with hypothesis test?
how to generate massive data with hypothesis test?
Dec 18, 2023
zhoucheng361
changed the title
how to generate massive data with hypothesis test?
how to make hypothesis stateful test to run enough steps in one example?
Dec 18, 2023
Hypothesis is designed around hundreds of at most thousands of elements, because we've found this is a sweet spot for rigorous but reasonably quick testing.
I have a hypothesis stateful test including some posix operations like create/open/mkdir/unlink/read/write etc. I want use this the stateful test to generate a complex directory structure including lots of directories and files, used for other tests.
I try to set max_examples to 1 and stateful_step_count to 10000,but it will finish in a few steps.
Is there a way to make sure I can run enough steps to generate massive data?
This is some of the test code:
import os
from string import ascii_lowercase
from hypothesis import Verbosity, assume, strategies as st
from hypothesis.stateful import rule, precondition, RuleBasedStateMachine, Bundle, initialize, consumes
from hypothesis import seed, settings
@settings(verbosity=Verbosity.debug,
max_examples=10,
stateful_step_count=10)
class PosixMachine(RuleBasedStateMachine):
if name == 'main':
juicefs_machine = PosixMachine.TestCase()
juicefs_machine.runTest()
The text was updated successfully, but these errors were encountered: