Patchwork [2,of,3] tests: Teach hypothesis to handle named shelves

login
register
mail settings
Submitter Simon Farnsworth
Date Feb. 22, 2016, 7:43 p.m.
Message ID <87c160b301c0c90be408.1456170221@dev1430.lla1.facebook.com>
Download mbox | patch
Permalink /patch/13298/
State Not Applicable
Headers show

Comments

Simon Farnsworth - Feb. 22, 2016, 7:43 p.m.
# HG changeset patch
# User Simon Farnsworth <simonfar@fb.com>
# Date 1456164414 28800
#      Mon Feb 22 10:06:54 2016 -0800
# Branch all
# Node ID 87c160b301c0c90be408e6a846cb9fcda4a828df
# Parent  7616a2b63284bb2670897a2e6c05815f39b6a6ed
tests: Teach hypothesis to handle named shelves

A more complex example of new, interacting rules.

Note that neither deleteshelve nor unshelve will be called until namedshelve
has created a shelve for them to operate on.

Patch

diff --git a/tests/test-verify-repo-operations.py b/tests/test-verify-repo-operations.py
--- a/tests/test-verify-repo-operations.py
+++ b/tests/test-verify-repo-operations.py
@@ -74,6 +74,8 @@ 
     lambda s: s.encode('ascii')
 )
 
+ShelveNames = st.text(PATH_CHARACTERS, min_size=1).map(lambda x: x.strip()).filter(
+    bool).filter(lambda x: x[0] != '-').map(lambda s: s.encode('ascii'))
 
 class VerifyingStateMachine(RuleBasedStateMachine):
     Repos = Bundle('repos')
@@ -81,6 +83,7 @@ 
     Contents = Bundle('contents')
     Branches = Bundle('branches')
     CommitTimes = Bundle('committimes')
+    Shelves = Bundle('shelvenames')
 
     def __init__(self):
         super(VerifyingStateMachine, self).__init__()
@@ -429,12 +432,31 @@ 
         with acceptable_errors("nothing changed"):
             self.hg("shelve")
 
+    @rule(name=ShelveNames, target=Shelves)
+    @precondition(lambda self: self.has_extension("shelve"))
+    def namedshelve(self, name):
+        with acceptable_errors("nothing changed"):
+            self.hg("shelve", "--name", name)
+        return name
+
     @rule()
     @precondition(lambda self: self.has_extension("shelve"))
     def unshelve(self):
         with acceptable_errors("no shelved changes to apply"):
             self.hg("unshelve")
 
+    @rule(name=Shelves)
+    @precondition(lambda self: self.has_extension("shelve"))
+    def namedunshelve(self, name):
+        with acceptable_errors("no shelved changes to apply",
+                               "shelved change '%s' not found" % (name,)):
+            self.hg("unshelve", name)
+
+    @rule(name=Shelves)
+    @precondition(lambda self: self.has_extension("shelve"))
+    def deleteshelve(self, name):
+        with acceptable_errors("shelved change '%s' not found" % (name,)):
+            self.hg("shelve", "--delete", name)
 
 class WriteOnlyDatabase(ExampleDatabase):
     def __init__(self, underlying):