Show More
@@ -108,6 +108,10 b' def acceptableerrors(*args):' | |||
|
108 | 108 | note(e.output) |
|
109 | 109 | raise |
|
110 | 110 | |
|
111 | reponames = st.text("abcdefghijklmnopqrstuvwxyz01234556789", min_size=1).map( | |
|
112 | lambda s: s.encode('ascii') | |
|
113 | ) | |
|
114 | ||
|
111 | 115 | class verifyingstatemachine(RuleBasedStateMachine): |
|
112 | 116 | """This defines the set of acceptable operations on a Mercurial repository |
|
113 | 117 | using Hypothesis's RuleBasedStateMachine. |
@@ -131,6 +135,7 b' class verifyingstatemachine(RuleBasedSta' | |||
|
131 | 135 | |
|
132 | 136 | # A bundle is a reusable collection of previously generated data which may |
|
133 | 137 | # be provided as arguments to future operations. |
|
138 | repos = Bundle('repos') | |
|
134 | 139 | paths = Bundle('paths') |
|
135 | 140 | contents = Bundle('contents') |
|
136 | 141 | branches = Bundle('branches') |
@@ -138,15 +143,17 b' class verifyingstatemachine(RuleBasedSta' | |||
|
138 | 143 | |
|
139 | 144 | def __init__(self): |
|
140 | 145 | super(verifyingstatemachine, self).__init__() |
|
141 | self.repodir = os.path.join(testtmp, "repo") | |
|
146 | self.repodir = os.path.join(testtmp, "repos") | |
|
142 | 147 | if os.path.exists(self.repodir): |
|
143 | 148 | shutil.rmtree(self.repodir) |
|
144 | 149 | os.chdir(testtmp) |
|
145 | 150 | self.log = [] |
|
146 | 151 | self.failed = False |
|
147 | 152 | |
|
148 | self.mkdirp("repo") | |
|
149 | self.cd("repo") | |
|
153 | self.mkdirp("repos") | |
|
154 | self.cd("repos") | |
|
155 | self.mkdirp("repo1") | |
|
156 | self.cd("repo1") | |
|
150 | 157 | self.hg("init") |
|
151 | 158 | |
|
152 | 159 | def teardown(self): |
@@ -356,6 +363,67 b' class verifyingstatemachine(RuleBasedSta' | |||
|
356 | 363 | with acceptableerrors(*errors): |
|
357 | 364 | self.hg(*command) |
|
358 | 365 | |
|
366 | # Section: Repository management | |
|
367 | @property | |
|
368 | def currentrepo(self): | |
|
369 | return os.path.basename(os.getcwd()) | |
|
370 | ||
|
371 | @rule( | |
|
372 | target=repos, | |
|
373 | source=repos, | |
|
374 | name=reponames, | |
|
375 | ) | |
|
376 | def clone(self, source, name): | |
|
377 | if not os.path.exists(os.path.join("..", name)): | |
|
378 | self.cd("..") | |
|
379 | self.hg("clone", source, name) | |
|
380 | self.cd(name) | |
|
381 | return name | |
|
382 | ||
|
383 | @rule( | |
|
384 | target=repos, | |
|
385 | name=reponames, | |
|
386 | ) | |
|
387 | def fresh(self, name): | |
|
388 | if not os.path.exists(os.path.join("..", name)): | |
|
389 | self.cd("..") | |
|
390 | self.mkdirp(name) | |
|
391 | self.cd(name) | |
|
392 | self.hg("init") | |
|
393 | return name | |
|
394 | ||
|
395 | @rule(name=repos) | |
|
396 | def switch(self, name): | |
|
397 | self.cd(os.path.join("..", name)) | |
|
398 | assert self.currentrepo == name | |
|
399 | assert os.path.exists(".hg") | |
|
400 | ||
|
401 | @rule(target=repos) | |
|
402 | def origin(self): | |
|
403 | return "repo1" | |
|
404 | ||
|
405 | @rule() | |
|
406 | def pull(self, repo=repos): | |
|
407 | with acceptableerrors( | |
|
408 | "repository default not found", | |
|
409 | "repository is unrelated", | |
|
410 | ): | |
|
411 | self.hg("pull") | |
|
412 | ||
|
413 | @rule(newbranch=st.booleans()) | |
|
414 | def push(self, newbranch): | |
|
415 | with acceptableerrors( | |
|
416 | "default repository not configured", | |
|
417 | "no changes found", | |
|
418 | ): | |
|
419 | if newbranch: | |
|
420 | self.hg("push", "--new-branch") | |
|
421 | else: | |
|
422 | with acceptableerrors( | |
|
423 | "creates new branches" | |
|
424 | ): | |
|
425 | self.hg("push") | |
|
426 | ||
|
359 | 427 | # Section: Simple side effect free "check" operations |
|
360 | 428 | @rule() |
|
361 | 429 | def log(self): |
General Comments 0
You need to be logged in to leave comments.
Login now