Use black, enforce with GitHub Actions

This commit is contained in:
Alex Dempsey 2024-02-08 11:55:23 -08:00
parent c4620c3018
commit 8b23430a87
23 changed files with 4048 additions and 2797 deletions

View file

@ -1,5 +1,5 @@
#!/usr/bin/env python
'''
"""
test_cli.py - test brozzler commands
Copyright (C) 2017 Internet Archive
@ -15,7 +15,7 @@ distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
'''
"""
import brozzler.cli
import pkg_resources
@ -23,59 +23,62 @@ import pytest
import subprocess
import doublethink
def cli_commands():
commands = set(pkg_resources.get_entry_map(
'brozzler')['console_scripts'].keys())
commands.remove('brozzler-wayback')
commands = set(pkg_resources.get_entry_map("brozzler")["console_scripts"].keys())
commands.remove("brozzler-wayback")
try:
import gunicorn
except ImportError:
commands.remove('brozzler-dashboard')
commands.remove("brozzler-dashboard")
try:
import pywb
except ImportError:
commands.remove('brozzler-easy')
commands.remove("brozzler-easy")
return commands
@pytest.mark.parametrize('cmd', cli_commands())
@pytest.mark.parametrize("cmd", cli_commands())
def test_call_entrypoint(capsys, cmd):
entrypoint = pkg_resources.get_entry_map(
'brozzler')['console_scripts'][cmd]
entrypoint = pkg_resources.get_entry_map("brozzler")["console_scripts"][cmd]
callable = entrypoint.resolve()
with pytest.raises(SystemExit):
callable(['/whatever/bin/%s' % cmd, '--version'])
callable(["/whatever/bin/%s" % cmd, "--version"])
out, err = capsys.readouterr()
assert out == 'brozzler %s - %s\n' % (brozzler.__version__, cmd)
assert err == ''
assert out == "brozzler %s - %s\n" % (brozzler.__version__, cmd)
assert err == ""
@pytest.mark.parametrize('cmd', cli_commands())
@pytest.mark.parametrize("cmd", cli_commands())
def test_run_command(capsys, cmd):
proc = subprocess.Popen(
[cmd, '--version'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
[cmd, "--version"], stdout=subprocess.PIPE, stderr=subprocess.PIPE
)
out, err = proc.communicate()
assert err == b''
assert out == ('brozzler %s - %s\n' % (
brozzler.__version__, cmd)).encode('ascii')
assert err == b""
assert out == ("brozzler %s - %s\n" % (brozzler.__version__, cmd)).encode("ascii")
def test_rethinkdb_up():
'''Check that rethinkdb is up and running.'''
"""Check that rethinkdb is up and running."""
# check that rethinkdb is listening and looks sane
rr = doublethink.Rethinker(db='rethinkdb') # built-in db
rr = doublethink.Rethinker(db="rethinkdb") # built-in db
tbls = rr.table_list().run()
assert len(tbls) > 10
# XXX don't know why this test is failing in travis-ci and vagrant while
# test_call_entrypoint tests pass :( (also fails with capfd)
@pytest.mark.xfail
def test_stop_nonexistent_crawl(capsys):
with pytest.raises(SystemExit):
brozzler.cli.brozzler_stop_crawl(['brozzler-stop-crawl', '--site=123'])
brozzler.cli.brozzler_stop_crawl(["brozzler-stop-crawl", "--site=123"])
out, err = capsys.readouterr()
assert err.endswith('site not found with id=123\n')
assert out == ''
assert err.endswith("site not found with id=123\n")
assert out == ""
with pytest.raises(SystemExit):
brozzler.cli.brozzler_stop_crawl(['brozzler-stop-crawl', '--job=abc'])
brozzler.cli.brozzler_stop_crawl(["brozzler-stop-crawl", "--job=abc"])
out, err = capsys.readouterr()
assert err.endswith('''job not found with id='abc'\n''')
assert out == ''
assert err.endswith("""job not found with id='abc'\n""")
assert out == ""