Skip to content

Commit

Permalink
Merge pull request #293 from Anaconda-Platform/warnings
Browse files Browse the repository at this point in the history
Eliminate some warnings
  • Loading branch information
mcg1969 committed Dec 8, 2020
2 parents 2c6bb31 + e14e759 commit 4c1726d
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 37 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,9 @@ jobs:
run: |
source ./conda/etc/profile.d/conda.sh
conda activate anaconda-project-dev
if [ "$RUNNER_OS" == "Windows" ]; then COVERAGE=98; else COVERAGE=99; fi
pytest -vrfe --durations=10 \
--cov-config=.coveragerc --cov-report=term-missing \
--cov-fail-under=$COVERAGE --cov-report=xml:./coverage.xml \
--cov-fail-under=98 --cov-report=xml:./coverage.xml \
--cov=anaconda_project anaconda_project
- uses: codecov/codecov-action@v1
with:
Expand Down
13 changes: 4 additions & 9 deletions anaconda_project/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,20 +197,15 @@ def download(self, project, project_dir=None, parent_dir=None):
class _UploadedStatus(SimpleStatus):
def __init__(self, json):
self.url = json.get('url', None)
logs = []
if self.url is not None:
logs.append("Project is at %s" % self.url)
super(_UploadedStatus, self).__init__(success=True, description="Upload successful.", logs=logs)
msg = 'Upload successful' + ('.' if self.url is None else ': ' + self.url)
super(_UploadedStatus, self).__init__(success=True, description=msg)


class _DownloadedStatus(SimpleStatus):
def __init__(self, filename):
self.filename = filename
logs = []
if self.filename is not None:
logs.append("Project is at %s" % self.filename)

super(_DownloadedStatus, self).__init__(success=True, description="Download successful.", logs=logs)
msg = 'Download successful' + ('.' if filename is None else ': ' + filename)
super(_DownloadedStatus, self).__init__(success=True, description=msg)


# This function is supposed to encapsulate the binstar API (don't
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class FakeRequirementStatus(object):
def __init__(self, success, status_description):
self.status_description = status_description
self.success = success
self.logs = ["This is a log message."]
self.errors = []
if not success:
self.errors.append("This is an error message.")
Expand Down
10 changes: 7 additions & 3 deletions anaconda_project/internal/py2_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@
# -----------------------------------------------------------------------------
from __future__ import absolute_import, print_function

import collections
import platform
import sys

try: # pragma: no cover
from collections.abc import Mapping, Sequence
except ImportError:
from collections import Mapping, Sequence

_PY2 = sys.version_info[0] == 2


Expand All @@ -29,11 +33,11 @@ def is_string(s):


def is_list(v):
return isinstance(v, collections.Sequence) and not is_string(v)
return isinstance(v, Sequence) and not is_string(v)


def is_dict(v):
return isinstance(v, collections.Mapping)
return isinstance(v, Mapping)


def env_without_unicode(environ):
Expand Down
6 changes: 1 addition & 5 deletions anaconda_project/internal/simple_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,14 @@
"""The SimpleStatus type, a status with no extra info."""
from __future__ import absolute_import

import warnings

from anaconda_project.status import Status


class SimpleStatus(Status):
def __init__(self, success, description, logs=(), errors=()):
def __init__(self, success, description, errors=()):
self._success = success
self._description = description
self._errors = list(errors)
if len(logs) > 0:
warnings.warn("Don't pass logs to SimpleStatus", DeprecationWarning)

def __bool__(self):
return self._success
Expand Down
6 changes: 5 additions & 1 deletion anaconda_project/internal/test/http_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,13 @@ def url(self):
def start(self):
self._http.start(1)

@gen.coroutine
def close_all(self):
self._http.close_all_connections()

def unlisten(self):
self._http.close_all_connections()
self._http.stop()
yield self.close_all()

@property
def error_url(self):
Expand Down
6 changes: 2 additions & 4 deletions anaconda_project/internal/test/test_simple_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@


def test_simple_status_properties():
good_status = SimpleStatus(success=True, description="quick brown fox", logs=["foo"], errors=["bar"])
good_status = SimpleStatus(success=True, description="quick brown fox", errors=["bar"])
assert good_status
assert good_status.status_description == "quick brown fox"
assert good_status.logs == ()
assert good_status.errors == ["bar"]

bad_status = SimpleStatus(success=False, description="quick brown fox", logs=["foo"], errors=["bar"])
bad_status = SimpleStatus(success=False, description="quick brown fox", errors=["bar"])
assert not bad_status
assert bad_status.status_description == "quick brown fox"
assert bad_status.logs == ()
assert bad_status.errors == ["bar"]
4 changes: 1 addition & 3 deletions anaconda_project/project_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -1511,7 +1511,6 @@ def add_service(project, env_spec_name, service_type, variable_name=None):
if found is None:
return SimpleStatus(success=False,
description="Unable to add service.",
logs=[],
errors=[
"Unknown service type '%s', we know about: %s" %
(service_type, ", ".join(map(lambda s: s.name, known_types)))
Expand All @@ -1532,15 +1531,14 @@ def add_service(project, env_spec_name, service_type, variable_name=None):
# redis in test_project_ops.py::test_add_service_already_exists_with_different_type
# and then uncomment the below code.
# if requirement.service_type != service_type:
# return SimpleStatus(success=False, description="Unable to add service.", logs=[],
# return SimpleStatus(success=False, description="Unable to add service.",
# errors=["Service %s already exists but with type '%s'" %
# (variable_name, requirement.service_type)])
# else:
requirement_already_exists = True
else:
return SimpleStatus(success=False,
description="Unable to add service.",
logs=[],
errors=["Variable %s is already in use." % variable_name])

if not requirement_already_exists:
Expand Down
8 changes: 0 additions & 8 deletions anaconda_project/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
"""The Status type."""
from __future__ import absolute_import

import warnings

from abc import ABCMeta, abstractmethod

from anaconda_project.internal.metaclass import with_metaclass
Expand All @@ -33,12 +31,6 @@ def status_description(self):
"""Get a one-line-ish description of the status."""
pass # pragma: no cover

@property
def logs(self):
"""Get logs relevant to the status."""
warnings.warn("Provide a Frontend object instead of using status.logs", DeprecationWarning)
return ()

@property
@abstractmethod
def errors(self):
Expand Down
7 changes: 6 additions & 1 deletion anaconda_project/test/fake_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from tornado.httpserver import HTTPServer
from tornado.netutil import bind_sockets
from tornado.web import Application, RequestHandler
from tornado import gen


class ProjectViewHandler(RequestHandler):
Expand Down Expand Up @@ -141,10 +142,14 @@ def port(self):
def url(self):
return "http://localhost:%d/" % self.port

@gen.coroutine
def close_all(self):
self._http.close_all_connections()

def unlisten(self):
"""Permanently close down the HTTP server, no longer listen on any sockets."""
self._http.close_all_connections()
self._http.stop()
yield self.close_all()


def _monkeypatch_client_config(monkeypatch, url):
Expand Down
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ tag_prefix = v
parentdir_prefix = anaconda_project-

[tool:pytest]
markers =
slow: marks tests as slow (deselect with '-m "not slow"')
norecursedirs= .* *.egg* build bin dist conda.recipe scripts examples
addopts =
-vrfe
Expand Down

0 comments on commit 4c1726d

Please sign in to comment.