diff tests/test-verify-repo-operations.py @ 43076:2372284d9457

formatting: blacken the codebase This is using my patch to black (https://github.com/psf/black/pull/826) so we don't un-wrap collection literals. Done with: hg files 'set:**.py - mercurial/thirdparty/** - "contrib/python-zstandard/**"' | xargs black -S # skip-blame mass-reformatting only # no-check-commit reformats foo_bar functions Differential Revision: https://phab.mercurial-scm.org/D6971
author Augie Fackler <augie@google.com>
date Sun, 06 Oct 2019 09:45:02 -0400
parents 8b90367c4cf3
children 89a2afe31e82
line wrap: on
line diff
--- a/tests/test-verify-repo-operations.py	Sat Oct 05 10:29:34 2019 -0400
+++ b/tests/test-verify-repo-operations.py	Sun Oct 06 09:45:02 2019 -0400
@@ -11,8 +11,7 @@
 import sys
 
 # Only run if slow tests are allowed
-if subprocess.call(['python', '%s/hghave' % os.environ['TESTDIR'],
-                    'slow']):
+if subprocess.call(['python', '%s/hghave' % os.environ['TESTDIR'], 'slow']):
     sys.exit(80)
 
 # These tests require Hypothesis and pytz to be installed.
@@ -29,6 +28,7 @@
 # fix this problem.
 try:
     import enum
+
     assert enum  # Silence pyflakes
 except ImportError:
     sys.stderr.write("skipped: enum34 not installed" + os.linesep)
@@ -44,7 +44,11 @@
 
 from hypothesis.errors import HypothesisException
 from hypothesis.stateful import (
-    rule, RuleBasedStateMachine, Bundle, precondition)
+    rule,
+    RuleBasedStateMachine,
+    Bundle,
+    precondition,
+)
 from hypothesis import settings, note, strategies as st
 from hypothesis.configuration import set_hypothesis_home_dir
 from hypothesis.database import ExampleDatabase
@@ -76,9 +80,9 @@
 file_index = 0
 while True:
     file_index += 1
-    savefile = os.path.join(generatedtests, "test-generated-%d.t" % (
-        file_index,
-    ))
+    savefile = os.path.join(
+        generatedtests, "test-generated-%d.t" % (file_index,)
+    )
     try:
         os.close(os.open(savefile, os.O_CREAT | os.O_EXCL | os.O_WRONLY))
         break
@@ -94,17 +98,23 @@
     "[]^_`;=@{}~ !#$%&'()+,-"
 )
 
-files = st.text(filecharacters, min_size=1).map(lambda x: x.strip()).filter(
-    bool).map(lambda s: s.encode('ascii'))
-
-safetext = st.text(st.characters(
-    min_codepoint=1, max_codepoint=127,
-    blacklist_categories=('Cc', 'Cs')), min_size=1).map(
-    lambda s: s.encode('utf-8')
+files = (
+    st.text(filecharacters, min_size=1)
+    .map(lambda x: x.strip())
+    .filter(bool)
+    .map(lambda s: s.encode('ascii'))
 )
 
+safetext = st.text(
+    st.characters(
+        min_codepoint=1, max_codepoint=127, blacklist_categories=('Cc', 'Cs')
+    ),
+    min_size=1,
+).map(lambda s: s.encode('utf-8'))
+
 extensions = st.sampled_from(('shelve', 'mq', 'blackbox',))
 
+
 @contextmanager
 def acceptableerrors(*args):
     """Sometimes we know an operation we're about to perform might fail, and
@@ -118,10 +128,12 @@
             note(e.output)
             raise
 
+
 reponames = st.text("abcdefghijklmnopqrstuvwxyz01234556789", min_size=1).map(
     lambda s: s.encode('ascii')
 )
 
+
 class verifyingstatemachine(RuleBasedStateMachine):
     """This defines the set of acceptable operations on a Mercurial repository
     using Hypothesis's RuleBasedStateMachine.
@@ -188,8 +200,10 @@
             o.write(ttest + os.linesep)
         with open(os.devnull, "w") as devnull:
             rewriter = subprocess.Popen(
-                [runtests, "--local", "-i", path], stdin=subprocess.PIPE,
-                stdout=devnull, stderr=devnull,
+                [runtests, "--local", "-i", path],
+                stdin=subprocess.PIPE,
+                stdout=devnull,
+                stderr=devnull,
             )
             rewriter.communicate("yes")
             with open(path, 'r') as i:
@@ -198,29 +212,29 @@
         e = None
         if not self.failed:
             try:
-                output = subprocess.check_output([
-                    runtests, path, "--local", "--pure"
-                ], stderr=subprocess.STDOUT)
+                output = subprocess.check_output(
+                    [runtests, path, "--local", "--pure"],
+                    stderr=subprocess.STDOUT,
+                )
                 assert "Ran 1 test" in output, output
-                for ext in (
-                    self.all_extensions - self.non_skippable_extensions
-                ):
-                    tf = os.path.join(testtmp, "test-generated-no-%s.t" % (
-                        ext,
-                    ))
+                for ext in self.all_extensions - self.non_skippable_extensions:
+                    tf = os.path.join(
+                        testtmp, "test-generated-no-%s.t" % (ext,)
+                    )
                     with open(tf, 'w') as o:
                         for l in ttest.splitlines():
                             if l.startswith("  $ hg"):
                                 l = l.replace(
-                                    "--config %s=" % (
-                                        extensionconfigkey(ext),), "")
+                                    "--config %s=" % (extensionconfigkey(ext),),
+                                    "",
+                                )
                             o.write(l + os.linesep)
                     with open(tf, 'r') as r:
                         t = r.read()
                         assert ext not in t, t
-                    output = subprocess.check_output([
-                        runtests, tf, "--local",
-                    ], stderr=subprocess.STDOUT)
+                    output = subprocess.check_output(
+                        [runtests, tf, "--local",], stderr=subprocess.STDOUT
+                    )
                     assert "Ran 1 test" in output, output
             except subprocess.CalledProcessError as e:
                 note(e.output)
@@ -244,7 +258,8 @@
         if os.path.exists(path):
             return
         self.log.append(
-            "$ mkdir -p -- %s" % (pipes.quote(os.path.relpath(path)),))
+            "$ mkdir -p -- %s" % (pipes.quote(os.path.relpath(path)),)
+        )
         os.makedirs(path)
 
     def cd(self, path):
@@ -270,28 +285,29 @@
     # to use later.
     @rule(
         target=paths,
-        source=st.lists(files, min_size=1).map(lambda l: os.path.join(*l)))
+        source=st.lists(files, min_size=1).map(lambda l: os.path.join(*l)),
+    )
     def genpath(self, source):
         return source
 
     @rule(
         target=committimes,
-        when=datetimes(min_year=1970, max_year=2038) | st.none())
+        when=datetimes(min_year=1970, max_year=2038) | st.none(),
+    )
     def gentime(self, when):
         return when
 
     @rule(
         target=contents,
         content=st.one_of(
-            st.binary(),
-            st.text().map(lambda x: x.encode('utf-8'))
-        ))
+            st.binary(), st.text().map(lambda x: x.encode('utf-8'))
+        ),
+    )
     def gencontent(self, content):
         return content
 
     @rule(
-        target=branches,
-        name=safetext,
+        target=branches, name=safetext,
     )
     def genbranch(self, name):
         return name
@@ -322,12 +338,13 @@
                 return
         with open(path, 'wb') as o:
             o.write(content)
-        self.log.append((
-            "$ python -c 'import binascii; "
-            "print(binascii.unhexlify(\"%s\"))' > %s") % (
-                binascii.hexlify(content),
-                pipes.quote(path),
-            ))
+        self.log.append(
+            (
+                "$ python -c 'import binascii; "
+                "print(binascii.unhexlify(\"%s\"))' > %s"
+            )
+            % (binascii.hexlify(content), pipes.quote(path),)
+        )
 
     @rule(path=paths)
     def addpath(self, path):
@@ -337,9 +354,7 @@
     @rule(path=paths)
     def forgetpath(self, path):
         if os.path.exists(path):
-            with acceptableerrors(
-                "file is already untracked",
-            ):
+            with acceptableerrors("file is already untracked",):
                 self.hg("forget", "--", path)
 
     @rule(s=st.none() | st.integers(0, 100))
@@ -388,8 +403,9 @@
                 errors.append('negative date value')
             if when.year == 2038:
                 errors.append('exceeds 32 bits')
-            command.append("--date=%s" % (
-                when.strftime('%Y-%m-%d %H:%M:%S %z'),))
+            command.append(
+                "--date=%s" % (when.strftime('%Y-%m-%d %H:%M:%S %z'),)
+            )
 
         with acceptableerrors(*errors):
             self.hg(*command)
@@ -404,9 +420,7 @@
         return self.configperrepo.setdefault(self.currentrepo, {})
 
     @rule(
-        target=repos,
-        source=repos,
-        name=reponames,
+        target=repos, source=repos, name=reponames,
     )
     def clone(self, source, name):
         if not os.path.exists(os.path.join("..", name)):
@@ -416,8 +430,7 @@
         return name
 
     @rule(
-        target=repos,
-        name=reponames,
+        target=repos, name=reponames,
     )
     def fresh(self, name):
         if not os.path.exists(os.path.join("..", name)):
@@ -440,23 +453,19 @@
     @rule()
     def pull(self, repo=repos):
         with acceptableerrors(
-            "repository default not found",
-            "repository is unrelated",
+            "repository default not found", "repository is unrelated",
         ):
             self.hg("pull")
 
     @rule(newbranch=st.booleans())
     def push(self, newbranch):
         with acceptableerrors(
-            "default repository not configured",
-            "no changes found",
+            "default repository not configured", "no changes found",
         ):
             if newbranch:
                 self.hg("push", "--new-branch")
             else:
-                with acceptableerrors(
-                    "creates new branches"
-                ):
+                with acceptableerrors("creates new branches"):
                     self.hg("push")
 
     # Section: Simple side effect free "check" operations
@@ -498,8 +507,7 @@
     @rule(branch=branches, clean=st.booleans())
     def update(self, branch, clean):
         with acceptableerrors(
-            'unknown revision',
-            'parse error',
+            'unknown revision', 'parse error',
         ):
             if clean:
                 self.hg("update", "-C", "--", branch)
@@ -538,6 +546,7 @@
         with acceptableerrors("no shelved changes to apply"):
             self.hg("unshelve")
 
+
 class writeonlydatabase(ExampleDatabase):
     def __init__(self, underlying):
         super(ExampleDatabase, self).__init__()
@@ -555,35 +564,35 @@
     def close(self):
         self.underlying.close()
 
+
 def extensionconfigkey(extension):
     return "extensions." + extension
 
+
 settings.register_profile(
-    'default',  settings(
-        timeout=300,
-        stateful_step_count=50,
-        max_examples=10,
-    )
+    'default', settings(timeout=300, stateful_step_count=50, max_examples=10,)
 )
 
 settings.register_profile(
-    'fast',  settings(
+    'fast',
+    settings(
         timeout=10,
         stateful_step_count=20,
         max_examples=5,
         min_satisfying_examples=1,
         max_shrinks=0,
-    )
+    ),
 )
 
 settings.register_profile(
-    'continuous', settings(
+    'continuous',
+    settings(
         timeout=-1,
         stateful_step_count=1000,
         max_examples=10 ** 8,
         max_iterations=10 ** 8,
-        database=writeonlydatabase(settings.default.database)
-    )
+        database=writeonlydatabase(settings.default.database),
+    ),
 )
 
 settings.load_profile(os.getenv('HYPOTHESIS_PROFILE', 'default'))