Skip to content

Commit

Permalink
Merge pull request mtreinish#321 from masayukig/deprecate-repo_type
Browse files Browse the repository at this point in the history
Deprecate repo_type parameter in get_repo_open and get_repo_initialise
  • Loading branch information
mtreinish authored Apr 13, 2022
2 parents ba5995e + 011c84d commit 3b5803c
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 19 deletions.
2 changes: 1 addition & 1 deletion stestr/commands/failing.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def failing(repo_url=None, list_tests=False, subunit=False,
for failures.
:rtype: int
"""
repo = util.get_repo_open('file', repo_url)
repo = util.get_repo_open(repo_url=repo_url)
run = repo.get_failing()
if subunit:
return _show_subunit(run)
Expand Down
6 changes: 3 additions & 3 deletions stestr/commands/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def history_list(repo_url=None, show_metadata=False,
else:
field_names = ('Run ID', 'Passed', 'Runtime', 'Date')
try:
repo = util.get_repo_open('file', repo_url)
repo = util.get_repo_open(repo_url=repo_url)
except abstract.RepositoryNotFound as e:
stdout.write(str(e) + '\n')
return 1
Expand Down Expand Up @@ -285,7 +285,7 @@ def history_show(run_id, repo_url=None, subunit_out=False,
:rtype: int
"""
try:
repo = util.get_repo_open('file', repo_url)
repo = util.get_repo_open(repo_url=repo_url)
except abstract.RepositoryNotFound as e:
stdout.write(str(e) + '\n')
return 1
Expand Down Expand Up @@ -352,7 +352,7 @@ def history_remove(run_id, repo_url=None, stdout=sys.stdout):
:rtype: int
"""
try:
repo = util.get_repo_open('file', repo_url)
repo = util.get_repo_open(repo_url=repo_url)
except abstract.RepositoryNotFound as e:
stdout.write(str(e) + '\n')
return 1
Expand Down
2 changes: 1 addition & 1 deletion stestr/commands/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def init(repo_url=None, stdout=sys.stdout):
:rtype: int
"""
try:
util.get_repo_initialise('file', repo_url)
util.get_repo_initialise(repo_url=repo_url)
except OSError as e:
if e.errno != errno.EEXIST:
raise
Expand Down
2 changes: 1 addition & 1 deletion stestr/commands/last.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def last(repo_url=None, subunit_out=False, pretty_out=True,
:rtype: int
"""
try:
repo = util.get_repo_open('file', repo_url)
repo = util.get_repo_open(repo_url=repo_url)
except abstract.RepositoryNotFound as e:
stdout.write(str(e) + '\n')
return 1
Expand Down
4 changes: 2 additions & 2 deletions stestr/commands/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,11 @@ def load(force_init=False, in_streams=None,
:rtype: int
"""
try:
repo = util.get_repo_open('file', repo_url)
repo = util.get_repo_open(repo_url=repo_url)
except repository.RepositoryNotFound:
if force_init:
try:
repo = util.get_repo_initialise('file', repo_url)
repo = util.get_repo_initialise(repo_url=repo_url)
except OSError as e:
if e.errno != errno.EEXIST:
raise
Expand Down
6 changes: 3 additions & 3 deletions stestr/commands/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ def run_command(config='.stestr.conf',
:rtype: int
"""
try:
repo = util.get_repo_open('file', repo_url)
repo = util.get_repo_open(repo_url=repo_url)
# If a repo is not found, and there a stestr config exists just create it
except repository.RepositoryNotFound:
if not os.path.isfile(config) and not test_path:
Expand All @@ -380,7 +380,7 @@ def run_command(config='.stestr.conf',
stdout.write(msg)
exit(1)
try:
repo = util.get_repo_initialise('file', repo_url)
repo = util.get_repo_initialise(repo_url=repo_url)
except OSError as e:
if e.errno != errno.EEXIST:
raise
Expand Down Expand Up @@ -634,7 +634,7 @@ def run_tests():
# the result from the repository because load() returns 0
# always on subunit output
if subunit_out:
repo = util.get_repo_open('file', repo_url)
repo = util.get_repo_open(repo_url=repo_url)
summary = testtools.StreamSummary()
last_run = repo.get_latest_run().get_subunit_stream()
stream = subunit.ByteStreamToStreamResult(last_run)
Expand Down
2 changes: 1 addition & 1 deletion stestr/commands/slowest.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def slowest(repo_url=None, show_all=False,
:rtype: int
"""

repo = util.get_repo_open('file', repo_url)
repo = util.get_repo_open(repo_url=repo_url)
try:
latest_id = repo.latest_id()
except KeyError:
Expand Down
2 changes: 1 addition & 1 deletion stestr/config_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def group_callback(test_id, regex=re.compile(group_regex)):
else:
group_callback = None
# Handle the results repository
repository = util.get_repo_open('file', repo_url)
repository = util.get_repo_open(repo_url=repo_url)
return test_processor.TestProcessorFixture(
test_ids, command, listopt, idoption, repository,
test_filters=regexes, group_callback=group_callback, serial=serial,
Expand Down
23 changes: 19 additions & 4 deletions stestr/repository/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import importlib
import os
import warnings


def _get_default_repo_url(repo_type):
Expand All @@ -22,26 +23,40 @@ def _get_default_repo_url(repo_type):
return repo_url


def get_repo_open(repo_type, repo_url=None):
def get_repo_open(repo_type=None, repo_url=None):
"""Return an already initialized repo object given the parameters
:param str repo_type: The repo module to use for the returned repo
:param str repo_type: DEPRECATED - The repo module to use for the returned
repo
:param str repo_url: An optional repo url, if one is not specified the
default $CWD/.stestr will be used.
"""
if repo_type is not None:
msg = ("WARNING: Specifying repository type is deprecated and will be "
"removed in future release.\n")
warnings.warn(msg, DeprecationWarning, stacklevel=3)
else:
repo_type = 'file'
repo_module = importlib.import_module('stestr.repository.' + repo_type)
if not repo_url:
repo_url = _get_default_repo_url(repo_type)
return repo_module.RepositoryFactory().open(repo_url)


def get_repo_initialise(repo_type, repo_url=None):
def get_repo_initialise(repo_type=None, repo_url=None):
"""Return a newly initialized repo object given the parameters
:param str repo_type: The repo module to use for the returned repo
:param str repo_type: DEPRECATED - The repo module to use for the returned
repo
:param str repo_url: An optional repo url, if one is not specified the
default $CWD/.stestr will be used.
"""
if repo_type is not None:
msg = ("WARNING: Specifying repository type is deprecated and will be "
"removed in future release.\n")
warnings.warn(msg, DeprecationWarning, stacklevel=3)
else:
repo_type = 'file'
repo_module = importlib.import_module('stestr.repository.' + repo_type)
if not repo_url:
repo_url = _get_default_repo_url(repo_type)
Expand Down
3 changes: 1 addition & 2 deletions stestr/tests/test_config_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ def _check_get_run_command(self, mock_sys, mock_TestProcessorFixture,
parallel_class=parallel_class)

self.assertEqual(mock_TestProcessorFixture.return_value, fixture)
mock_get_repo_open.assert_called_once_with('file',
None)
mock_get_repo_open.assert_called_once_with(repo_url=None)
command = '"%s" -m stestr.subunit_runner.run discover -t "%s" "%s" ' \
'$LISTOPT $IDOPTION' % (expected_python, 'fake_top_dir',
'fake_test_path')
Expand Down

0 comments on commit 3b5803c

Please sign in to comment.