Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reformat the code with black #3367

Merged
merged 3 commits into from
May 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,13 @@ tests:
PATH="/opt/warehouse/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" \
bin/tests --postgresql-host db $(T) $(TESTARGS)


reformat: .state/env/pyvenv.cfg
$(BINDIR)/black warehouse/ tests/

lint: .state/env/pyvenv.cfg
$(BINDIR)/flake8 .
$(BINDIR)/black --check warehouse/ tests/
$(BINDIR)/doc8 --allow-long-titles README.rst CONTRIBUTING.rst docs/ --ignore-path docs/_build/
# TODO: Figure out a solution to https://github.com/deezer/template-remover/issues/1
# so we can remove extra_whitespace from below.
Expand All @@ -122,8 +127,10 @@ deps: .state/env/pyvenv.cfg
$(eval TMPDIR := $(shell mktemp -d))
$(BINDIR)/pip-compile --no-annotate --no-header --upgrade --allow-unsafe -o $(TMPDIR)/deploy.txt requirements/deploy.in > /dev/null
$(BINDIR)/pip-compile --no-annotate --no-header --upgrade --allow-unsafe -o $(TMPDIR)/main.txt requirements/main.in > /dev/null
$(BINDIR)/pip-compile --no-annotate --no-header --upgrade --allow-unsafe -o $(TMPDIR)/lint.txt requirements/lint.in > /dev/null
echo "$$DEPCHECKER" | python - $(TMPDIR)/deploy.txt requirements/deploy.txt
echo "$$DEPCHECKER" | python - $(TMPDIR)/main.txt requirements/main.txt
echo "$$DEPCHECKER" | python - $(TMPDIR)/lint.txt requirements/lint.txt
rm -r $(TMPDIR)
$(BINDIR)/pip check

Expand Down
1 change: 1 addition & 0 deletions requirements/lint.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ doc8
flake8
html-linter
pep8-naming
black==18.5b0
12 changes: 12 additions & 0 deletions requirements/lint.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
appdirs==1.4.3 \
--hash=sha256:9e5896d1372858f8dd3344faf4e5014d21849c756c8d5701f78f8a103b372d92 \
--hash=sha256:d8b24664561d0d34ddfaec54636d502d7cea6e29c3eaf68f3df6180863e2166e
attrs==18.1.0 \
--hash=sha256:4b90b09eeeb9b88c35bc642cbac057e45a5fd85367b985bd2809c62b7b939265 \
--hash=sha256:e0d0eb91441a3b53dab4d9b743eafc1ac44476296a2053b6ca3af0b139faf87b
black==18.5b0 \
--hash=sha256:4fec2566f9fbbd4a58de50a168cbe3ab952713530410d227e82e4c65d1fad946 \
--hash=sha256:5fec0f25486046b9edb97961c946412ced96021247dd1a60ecd9f0567b68b030
chardet==3.0.4 \
--hash=sha256:fc323ffcaeaed0e0a02bf4d117757b98aed530d9ed4531e3e15460124c106691 \
--hash=sha256:84ab92ed1c4d4f16916e05906b6b75a6c0fb5db821cc65e70cbd64a3e2a5eaae
click==6.7 \
--hash=sha256:29f99fc6125fbc931b758dc053b3114e55c77a6e4c6c3a2674a2dc986016381d \
--hash=sha256:f15516df478d5a56180fbf80e68f206010e6d160fc39fa508b65e035fd75130b
doc8==0.8.0 \
--hash=sha256:d12f08aa77a4a65eb28752f4bc78f41f611f9412c4155e2b03f1f5d4a45efe04 \
--hash=sha256:2df89f9c1a5abfb98ab55d0175fed633cae0cf45025b8b1e0ee5ea772be28543
Expand Down
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
[flake8]
max-line-length = 88
exclude = *.egg,*/interfaces.py,node_modules,.state
ignore = W503,E203
select = E,W,F,N

[tool:pytest]
Expand Down
9 changes: 4 additions & 5 deletions tests/common/db/accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@


class UserFactory(WarehouseFactory):

class Meta:
model = User

Expand All @@ -31,15 +32,13 @@ class Meta:
is_staff = False
is_superuser = False
date_joined = factory.fuzzy.FuzzyNaiveDateTime(
datetime.datetime(2005, 1, 1),
datetime.datetime(2010, 1, 1),
)
last_login = factory.fuzzy.FuzzyNaiveDateTime(
datetime.datetime(2011, 1, 1),
datetime.datetime(2005, 1, 1), datetime.datetime(2010, 1, 1)
)
last_login = factory.fuzzy.FuzzyNaiveDateTime(datetime.datetime(2011, 1, 1))


class EmailFactory(WarehouseFactory):

class Meta:
model = Email

Expand Down
1 change: 1 addition & 0 deletions tests/common/db/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@


class AdminFlagFactory(WarehouseFactory):

class Meta:
model = AdminFlag

Expand Down
1 change: 1 addition & 0 deletions tests/common/db/classifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@


class ClassifierFactory(WarehouseFactory):

class Meta:
model = Classifier

Expand Down
42 changes: 26 additions & 16 deletions tests/common/db/packaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,30 @@
import packaging.utils

from warehouse.packaging.models import (
BlacklistedProject, Dependency, DependencyKind, File, JournalEntry,
Project, Release, Role,
BlacklistedProject,
Dependency,
DependencyKind,
File,
JournalEntry,
Project,
Release,
Role,
)

from .accounts import UserFactory
from .base import WarehouseFactory


class ProjectFactory(WarehouseFactory):

class Meta:
model = Project

name = factory.fuzzy.FuzzyText(length=12)


class ReleaseFactory(WarehouseFactory):

class Meta:
model = Release

Expand All @@ -49,6 +57,7 @@ class Meta:


class FileFactory(WarehouseFactory):

class Meta:
model = File

Expand All @@ -62,23 +71,23 @@ class Meta:
lambda o: hashlib.sha256(o.filename.encode("utf8")).hexdigest()
)
blake2_256_digest = factory.LazyAttribute(
lambda o: hashlib.blake2b(o.filename.encode("utf8"),
digest_size=32).hexdigest()
)
upload_time = factory.fuzzy.FuzzyNaiveDateTime(
datetime.datetime(2008, 1, 1)
lambda o: hashlib.blake2b(o.filename.encode("utf8"), digest_size=32).hexdigest()
)
upload_time = factory.fuzzy.FuzzyNaiveDateTime(datetime.datetime(2008, 1, 1))
path = factory.LazyAttribute(
lambda o: "/".join([
o.blake2_256_digest[:2],
o.blake2_256_digest[2:4],
o.blake2_256_digest[4:],
o.filename,
])
lambda o: "/".join(
[
o.blake2_256_digest[:2],
o.blake2_256_digest[2:4],
o.blake2_256_digest[4:],
o.filename,
]
)
)


class RoleFactory(WarehouseFactory):

class Meta:
model = Role

Expand All @@ -88,6 +97,7 @@ class Meta:


class DependencyFactory(WarehouseFactory):

class Meta:
model = Dependency

Expand All @@ -98,19 +108,19 @@ class Meta:


class JournalEntryFactory(WarehouseFactory):

class Meta:
model = JournalEntry

id = factory.Sequence(lambda n: n)
name = factory.fuzzy.FuzzyText(length=12)
version = factory.Sequence(lambda n: str(n) + ".0")
submitted_date = factory.fuzzy.FuzzyNaiveDateTime(
datetime.datetime(2008, 1, 1)
)
submitted_date = factory.fuzzy.FuzzyNaiveDateTime(datetime.datetime(2008, 1, 1))
submitted_by = factory.SubFactory(UserFactory)


class BlacklistedProjectFactory(WarehouseFactory):

class Meta:
model = BlacklistedProject

Expand Down
6 changes: 4 additions & 2 deletions tests/common/db/ses.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@


class EmailMessageFactory(WarehouseFactory):

class Meta:
model = EmailMessage

created = factory.fuzzy.FuzzyNaiveDateTime(
datetime.datetime.utcnow() - datetime.timedelta(days=14),
datetime.datetime.utcnow() - datetime.timedelta(days=14)
)
message_id = factory.fuzzy.FuzzyText(length=12)
from_ = FuzzyEmail()
Expand All @@ -34,11 +35,12 @@ class Meta:


class EventFactory(WarehouseFactory):

class Meta:
model = Event

created = factory.fuzzy.FuzzyNaiveDateTime(
datetime.datetime.utcnow() - datetime.timedelta(days=14),
datetime.datetime.utcnow() - datetime.timedelta(days=14)
)
email = factory.SubFactory(EmailMessageFactory)
event_id = factory.fuzzy.FuzzyText(length=12)
Expand Down
37 changes: 13 additions & 24 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
import webtest as _webtest

from pytest_postgresql.factories import (
init_postgresql_database, drop_postgresql_database, get_config,
init_postgresql_database,
drop_postgresql_database,
get_config,
)
from sqlalchemy import event

Expand All @@ -39,19 +41,16 @@ def pytest_collection_modifyitems(items):
continue

module_path = os.path.relpath(
item.module.__file__,
os.path.commonprefix([__file__, item.module.__file__]),
item.module.__file__, os.path.commonprefix([__file__, item.module.__file__])
)

module_root_dir = module_path.split(os.pathsep)[0]
if (module_root_dir.startswith("functional")):
if module_root_dir.startswith("functional"):
item.add_marker(pytest.mark.functional)
elif module_root_dir.startswith("unit"):
item.add_marker(pytest.mark.unit)
else:
raise RuntimeError(
"Unknown test type (filename = {0})".format(module_path)
)
raise RuntimeError("Unknown test type (filename = {0})".format(module_path))


@pytest.fixture
Expand Down Expand Up @@ -87,7 +86,7 @@ def cli():
def database(request):
config = get_config(request)
pg_host = config.get("host")
pg_port = config.get("port") or os.environ.get('PGPORT', 5432)
pg_port = config.get("port") or os.environ.get("PGPORT", 5432)
pg_user = config.get("user")
pg_db = config.get("db", "tests")
pg_version = config.get("version", 10.1)
Expand Down Expand Up @@ -126,7 +125,7 @@ def app_config(database):
"sessions.url": "redis://localhost:0/",
"statuspage.url": "https://2p66nmmycsj3.statuspage.io",
"warehouse.xmlrpc.cache.url": "redis://localhost:0/",
},
}
)

# Ensure our migrations have been ran.
Expand Down Expand Up @@ -163,18 +162,12 @@ def restart_savepoint(session, transaction):

@pytest.yield_fixture
def user_service(db_session, app_config):
return services.DatabaseUserService(
db_session, app_config.registry.settings
)
return services.DatabaseUserService(db_session, app_config.registry.settings)


@pytest.yield_fixture
def token_service(app_config):
return services.TokenService(
secret="secret",
salt="salt",
max_age=21600,
)
return services.TokenService(secret="secret", salt="salt", max_age=21600)


class QueryRecorder:
Expand Down Expand Up @@ -257,13 +250,9 @@ def pytest_runtest_makereport(item, call):
if rep.when == "call" and rep.failed:
if "browser" in item.fixturenames:
browser = item.funcargs["browser"]
for log_type in (set(browser.log_types) - {"har"}):
for log_type in set(browser.log_types) - {"har"}:
data = "\n\n".join(
filter(
None,
(l.get("message") for l in browser.get_log(log_type)))
filter(None, (l.get("message") for l in browser.get_log(log_type)))
)
if data:
rep.sections.append(
("Captured {} log".format(log_type), data)
)
rep.sections.append(("Captured {} log".format(log_type), data))
7 changes: 4 additions & 3 deletions tests/functional/legacy_api/test_removed.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
@pytest.mark.parametrize("action", ["submit", "submit_pkg_info"])
def test_removed_upload_apis(webtest, action):
resp = webtest.post("/legacy/?:action={}".format(action), status=410)
assert resp.status == \
("410 Project pre-registration is no longer required or supported, "
"upload your files instead.")
assert resp.status == (
"410 Project pre-registration is no longer required or supported, "
"upload your files instead."
)


def test_remove_doc_upload(webtest):
Expand Down
11 changes: 2 additions & 9 deletions tests/functional/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,10 @@


@pytest.mark.parametrize(
('domain', 'indexable'),
[
('pypi.org', True),
('test.pypi.org', False),
]
("domain", "indexable"), [("pypi.org", True), ("test.pypi.org", False)]
)
def test_robots_txt(app_config, domain, indexable):
app_config.add_settings({
'warehouse.domain': domain,
'enforce_https': False,
})
app_config.add_settings({"warehouse.domain": domain, "enforce_https": False})
testapp = webtest.TestApp(app_config.make_wsgi_app())
resp = testapp.get("/robots.txt")
assert resp.status_code == 200
Expand Down
Loading