sapling/eden/integration/hg/lib/histedit_command.py
Adam Simpkins c3ebc91fdc update hg integration test inheritance to allow type checking
Summary:
Python 3 type checking currently complains about most of our integration
testing since the tests use an `hg_test` decorator to inherit from the base
test class.  This prevents the type checker from being able to figure out this
inheritance.

This updates all of the test cases to explicitly derive from the test case base
class, rather than using the decorator to do so.  I also renamed the base test
case class to `EdenHgTestCase` to be slightly more succinct and to follow the
common pattern of calling `unittest.TestCase` subclasses `FooTestCase`

Reviewed By: bolinfest

Differential Revision: D6268258

fbshipit-source-id: 09eef2f8217932a6516f78d17dddcd35c83b73da
2017-11-07 19:04:20 -08:00

45 lines
1.4 KiB
Python

#!/usr/bin/env python3
#
# Copyright (c) 2016-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree. An additional grant
# of patent rights can be found in the PATENTS file in the same directory.
from .hg_extension_test_base import EdenHgTestCase
import os
class HisteditCommand:
'''Utility to facilitate running `hg histedit` from an integration test.'''
def __init__(self):
self._actions = []
def pick(self, commit_hash: str) -> None:
self._actions.append('pick %s\n' % commit_hash)
def roll(self, commit_hash: str) -> None:
self._actions.append('roll %s\n' % commit_hash)
def drop(self, commit_hash: str) -> None:
self._actions.append('drop %s\n' % commit_hash)
def stop(self, commit_hash: str) -> None:
self._actions.append('stop %s\n' % commit_hash)
def run(self, test_base: EdenHgTestCase, ancestor: str = None) -> None:
commands_file = os.path.join(test_base.tmp_dir, 'histedit_commands.txt')
with open(commands_file, 'w') as f:
[f.write(action) for action in self._actions]
args = [
'histedit',
'--commands',
commands_file,
]
if ancestor is not None:
args.append(ancestor)
test_base.hg(*args)