Skip to content

Commit

Permalink
Merge branch 'develop' into 579-make-which-internal
Browse files Browse the repository at this point in the history
  • Loading branch information
ecederstrand committed Aug 29, 2021
2 parents 3b2f861 + 7cca5f8 commit 023ec4f
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 168 deletions.
1 change: 1 addition & 0 deletions .coveragerc
Expand Up @@ -2,6 +2,7 @@
branch = True
source =
sh.py
relative_files = True

[report]
exclude_lines =
Expand Down
53 changes: 53 additions & 0 deletions .github/workflows/run-tests.yml
@@ -0,0 +1,53 @@
# This workflow will install Python dependencies, run tests and converage with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Run tests

on: [push, pull_request]

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [2.7, 3.5, 3.6, 3.7, 3.8, 3.9, pypy2, pypy3]

steps:
- uses: actions/checkout@v2

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Upgrade pip
run: |
python -m pip install --upgrade pip
- name: Install dependencies
run: |
python -m pip install -r requirements-dev.txt
- name: 'Python2: Run tests'
if: matrix.python-version == '2.7' || matrix.python-version == 'pypy2'
run: |
python -m pip install .
SH_TESTS_RUNNING=1 SH_TESTS_USE_SELECT=0 LANG=C python -m unittest test
SH_TESTS_RUNNING=1 SH_TESTS_USE_SELECT=1 LANG=C python -m unittest test
SH_TESTS_RUNNING=1 SH_TESTS_USE_SELECT=0 LANG=en_US.UTF-8 python -m unittest test
SH_TESTS_RUNNING=1 SH_TESTS_USE_SELECT=1 LANG=en_US.UTF-8 python -m unittest test
- name: 'Python3: Run tests and report to Coveralls'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
if: matrix.python-version != '2.7' && matrix.python-version != 'pypy2'
run: |
python -m pip install coveralls==3.1.0
python -m pip install .
python -m flake8 sh.py test.py
python setup.py check --restructuredtext --metadata --strict
SH_TESTS_RUNNING=1 SH_TESTS_USE_SELECT=0 LANG=C coverage run -a --source=sh -m unittest
SH_TESTS_RUNNING=1 SH_TESTS_USE_SELECT=1 LANG=C coverage run -a --source=sh -m unittest
SH_TESTS_RUNNING=1 SH_TESTS_USE_SELECT=0 LANG=en_US.UTF-8 coverage run -a --source=sh -m unittest
SH_TESTS_RUNNING=1 SH_TESTS_USE_SELECT=1 LANG=en_US.UTF-8 coverage run -a --source=sh -m unittest
coveralls --service=github
28 changes: 0 additions & 28 deletions .travis.yml

This file was deleted.

4 changes: 2 additions & 2 deletions README.rst
Expand Up @@ -43,7 +43,7 @@ Installation
::

$> pip install sh

Support
=======
* `Andrew Moffat <https://github.com/amoffat>`_ - author/maintainer
Expand Down Expand Up @@ -85,7 +85,7 @@ Coverage

First run all of the tests::

$> python sh.py test
$> SH_TESTS_RUNNING=1 coverage run --source=sh -m unittest

This will aggregate a ``.coverage``. You may then visualize the report with::

Expand Down
3 changes: 1 addition & 2 deletions requirements-dev.txt
@@ -1,6 +1,5 @@
Pygments==2.1.3
coverage==4.2
coveralls==1.1
coverage==5.5
docopt==0.6.2
docutils==0.12
flake8==3.7.9
108 changes: 2 additions & 106 deletions sh.py
Expand Up @@ -3687,114 +3687,10 @@ def load_module(self, mod_fullname):
return module


def run_tests(env, locale, a, version, force_select, **extra_env): # pragma: no cover
py_version = "python"
py_version += str(version)

py_bin = _which(py_version)
return_code = None

poller = "poll"
if force_select:
poller = "select"

if py_bin:
print("Testing %s, locale %r, poller: %s" % (py_version.capitalize(), locale, poller))

env["SH_TESTS_USE_SELECT"] = str(int(force_select))
env["LANG"] = locale

for k, v in extra_env.items():
env[k] = str(v)

cmd = [py_bin, "-W", "ignore", os.path.join(THIS_DIR, "test.py")] + a[1:]
print("Running %r" % cmd)
return_code = os.spawnve(os.P_WAIT, cmd[0], cmd, env)

return return_code


def main(): # pragma: no cover
from optparse import OptionParser

parser = OptionParser()
parser.add_option("-e", "--envs", dest="envs", default=None, action="append")
parser.add_option("-l", "--locales", dest="constrain_locales", default=None, action="append")
options, parsed_args = parser.parse_args()

# these are essentially restrictions on what envs/constrain_locales to restrict to for
# the tests. if they're empty lists, it means use all available
action = None
if parsed_args:
action = parsed_args[0]

if action in ("test", "travis", "tox"):
import test
coverage = None
if test.HAS_UNICODE_LITERAL:
try:
import coverage
except ImportError:
pass

env = os.environ.copy()
env["SH_TESTS_RUNNING"] = "1"
if coverage:
test.append_module_path(env, coverage)

# if we're testing locally, run all versions of python on the system
if action == "test":
all_versions = ("2.6", "2.7", "3.1", "3.2", "3.3", "3.4", "3.5", "3.6", "3.7", "3.8", "3.9")

# if we're testing on travis or tox, just use the system's default python, since travis will spawn a vm per
# python version in our .travis.yml file, and tox will run its matrix via tox.ini
else:
v = sys.version_info
sys_ver = "%d.%d" % (v[0], v[1])
all_versions = (sys_ver,)

all_force_select = [True]
if HAS_POLL:
all_force_select.append(False)

all_locales = ("en_US.UTF-8", "C")
i = 0
ran_versions = set()
for locale in all_locales:
# make sure this locale is allowed
if options.constrain_locales and locale not in options.constrain_locales:
continue

for version in all_versions:
# make sure this version is allowed
if options.envs and version not in options.envs:
continue

for force_select in all_force_select:
env_copy = env.copy()

ran_versions.add(version)
exit_code = run_tests(env_copy, locale, parsed_args, version, force_select, SH_TEST_RUN_IDX=i)

if exit_code is None:
print("Couldn't find %s, skipping" % version)

elif exit_code != 0:
print("Failed for %s, %s" % (version, locale))
exit(1)

i += 1

print("Tested Python versions: %s" % ",".join(sorted(list(ran_versions))))

else:
env = Environment(globals())
run_repl(env)


if __name__ == "__main__": # pragma: no cover
# we're being run as a stand-alone script
main()
env = Environment(globals())
run_repl(env)
else:
# we're being imported from somewhere
sys.modules[__name__] = SelfWrapper(sys.modules[__name__])
Expand Down
31 changes: 1 addition & 30 deletions test.py
Expand Up @@ -23,33 +23,6 @@
IS_PY2 = not IS_PY3
MINOR_VER = sys.version_info[1]

# coverage doesn't work in python 3.1, 3.2 due to it just being a shit
# python
HAS_UNICODE_LITERAL = not (IS_PY3 and MINOR_VER in (1, 2))

cov = None
if HAS_UNICODE_LITERAL:
run_idx = int(os.environ.pop("SH_TEST_RUN_IDX", "0"))
first_run = run_idx == 0

try:
import coverage
except ImportError:
pass
else:
# for some reason, we can't run auto_data on the first run, or the coverage
# numbers get really screwed up
auto_data = True
if first_run:
auto_data = False

cov = coverage.Coverage(auto_data=auto_data)

if first_run:
cov.erase()

cov.start()

try:
import unittest.mock
except ImportError:
Expand Down Expand Up @@ -3212,6 +3185,4 @@ def test_reimport_from_cli(self):
exit(1)

finally:
if cov:
cov.stop()
cov.save()
pass

0 comments on commit 023ec4f

Please sign in to comment.