Skip to content

Commit

Permalink
Merge pull request #36 from pnuu/feature-github-actions
Browse files Browse the repository at this point in the history
Use GitHub Actions to run tests
  • Loading branch information
mraspaud committed Sep 1, 2021
2 parents 19e3995 + 4d6144b commit e06e90e
Show file tree
Hide file tree
Showing 10 changed files with 110 additions and 77 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Run tests

on:
- push
- pull_request

jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: true
matrix:
python-version: ["3.7", "3.8", "3.9"]
experimental: [false]
steps:
- name: Checkout source
uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
pip install -U pytest pytest-cov pyzmq netifaces
- name: Install posttroll
run: |
pip install --no-deps -e .
- name: Run tests
run: |
pytest --cov=posttroll posttroll/tests --cov-report=xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
with:
file: ./coverage.xml
env_vars: PYTHON_VERSION
Empty file added codecov.yml
Empty file.
16 changes: 8 additions & 8 deletions posttroll/listener.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Copyright (c) 2013, 2014

#
# Copyright (c) 2013, 2014, 2021 Pytroll community
#
# Author(s):

#
# Panu Lahtinen <panu.lahtinen@fmi.fi>
# Martin Raspaud <martin.raspaud@smhi.se>

#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.

#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

'''Listener module.'''

from posttroll.subscriber import NSSubscriber
from six.moves.queue import Queue
from queue import Queue
from threading import Thread
import time
import logging
Expand Down
26 changes: 13 additions & 13 deletions posttroll/message.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (c) 2010 - 2018 PyTroll Community

# Copyright (c) 2010 - 2018, 2021 PyTroll Community
#
# Author(s):

#
# Lars Ø. Rasmussen <ras@dmi.dk>
# Martin Raspaud <martin.raspaud@smhi.se>

# Panu Lahtinen <panu.lahtinen@fmi.fi>
#
# This file is part of PyTroll.

#
# Pytroll is free software: you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later
# version.

#
# Pytroll is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU General Public License for more details.

#
# You should have received a copy of the GNU General Public License along with
# pytroll. If not, see <http://www.gnu.org/licenses/>.

Expand All @@ -43,7 +44,6 @@
import json
except ImportError:
import simplejson as json
import six

from posttroll import strp_isoformat

Expand All @@ -67,19 +67,19 @@ class MessageError(Exception):
def is_valid_subject(obj):
"""Currently we only check for empty strings.
"""
return isinstance(obj, six.string_types) and bool(obj)
return isinstance(obj, str) and bool(obj)


def is_valid_type(obj):
"""Currently we only check for empty strings.
"""
return isinstance(obj, six.string_types) and bool(obj)
return isinstance(obj, str) and bool(obj)


def is_valid_sender(obj):
"""Currently we only check for empty strings.
"""
return isinstance(obj, six.string_types) and bool(obj)
return isinstance(obj, str) and bool(obj)


def is_valid_data(obj):
Expand Down Expand Up @@ -230,7 +230,7 @@ def datetime_decoder(dct):
pairs = dct.items()
result = []
for key, val in pairs:
if isinstance(val, six.string_types):
if isinstance(val, str):
try:
val = strp_isoformat(val)
except ValueError:
Expand Down Expand Up @@ -322,7 +322,7 @@ def _encode(msg, head=False, binary=False):
msg.subject, msg.type, msg.sender, msg.time.isoformat(), msg.version)

if not head and msg.data:
if not binary and isinstance(msg.data, six.string_types):
if not binary and isinstance(msg.data, str):
return (rawstr + ' ' +
'text/ascii' + ' ' + msg.data)
elif not binary:
Expand Down
20 changes: 10 additions & 10 deletions posttroll/ns.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Copyright (c) 2011, 2012, 2014, 2015 SMHI

#
# Copyright (c) 2011, 2012, 2014, 2015, 2021 Pytroll Community
#
# Author(s):

#
# Martin Raspaud <martin.raspaud@smhi.se>

# Panu Lahtinen <panu.lahtinen@fmi.fi"
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.

#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

Expand All @@ -29,7 +30,6 @@
import time
from datetime import datetime, timedelta

import six
from threading import Lock
# pylint: disable=E0611
from zmq import LINGER, NOBLOCK, POLLIN, REP, REQ, Poller
Expand Down Expand Up @@ -86,7 +86,7 @@ def get_pub_address(name, timeout=10, nameserver="localhost"):
poller.register(socket, POLLIN)

message = Message("/oper/ns", "request", {"service": name})
socket.send_string(six.text_type(message))
socket.send_string(str(message))

# Get the reply.
sock = poller.poll(timeout=timeout * 1000)
Expand Down Expand Up @@ -152,7 +152,7 @@ def run(self, *args):
logger.debug("Replying to request: " + str(msg))
msg = Message.decode(msg)
active_address = get_active_address(msg.data["service"], arec)
self.listener.send_unicode(six.text_type(active_address))
self.listener.send_unicode(str(active_address))
except KeyboardInterrupt:
# Needed to stop the nameserver.
pass
Expand Down
15 changes: 7 additions & 8 deletions posttroll/publisher.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (c) 2009-2015.
# Copyright (c) 2009-2015, 2021 Pytroll community
#
# Author(s):
# Lars Ørum Rasmussen <ras@dmi.dk>
# Martin Raspaud <martin.raspaud@smhi.se>

# Panu Lahtinen <panu.lahtinen@fmi.fi>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
Expand All @@ -19,17 +20,15 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#

"""The publisher module gives high-level tools to publish messages on a port.
"""
"""The publisher module gives high-level tools to publish messages on a port."""

import os
import logging
import socket
from datetime import datetime, timedelta
from threading import Lock
from six.moves.urllib.parse import urlsplit, urlunsplit
import six
from urllib.parse import urlsplit, urlunsplit
import zmq

from posttroll import get_context
Expand Down Expand Up @@ -194,7 +193,7 @@ def __init__(self, name, port=0, aliases=None, broadcast_interval=2,
self._name = name
self._aliases = [name]
if aliases:
if isinstance(aliases, six.string_types):
if isinstance(aliases, str):
self._aliases += [aliases]
else:
self._aliases += aliases
Expand Down
30 changes: 15 additions & 15 deletions posttroll/subscriber.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Copyright (c) 2011, 2012, 2013, 2014, 2015.

#
# Copyright (c) 2011, 2012, 2013, 2014, 2015, 2021 Pytroll community
#
# Author(s):

#
# Martin Raspaud <martin.raspaud@smhi.se>
# Lars Ø. Rasmussen <ras@dmi.dk>

# Panu Lahtinen <panu.lahtinen@fmi.fi>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.

#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

Expand All @@ -28,8 +29,7 @@
import time
from datetime import datetime, timedelta
from threading import Lock
from six.moves.urllib.parse import urlsplit
import six
from urllib.parse import urlsplit

# pylint: disable=E0611
from zmq import LINGER, NOBLOCK, POLLIN, PULL, SUB, SUBSCRIBE, Poller, ZMQError
Expand Down Expand Up @@ -101,7 +101,7 @@ def add(self, address, topics=None):
str(address), str(topics))
subscriber = get_context().socket(SUB)
for t__ in topics:
subscriber.setsockopt_string(SUBSCRIBE, six.text_type(t__))
subscriber.setsockopt_string(SUBSCRIBE, str(t__))
subscriber.connect(address)
self.sub_addr[subscriber] = address
self.addr_sub[address] = subscriber
Expand All @@ -128,7 +128,7 @@ def remove(self, address):
def update(self, addresses):
"""Updating with a set of addresses.
"""
if isinstance(addresses, six.string_types):
if isinstance(addresses, str):
addresses = [addresses, ]
s0_, s1_ = set(self.addresses), set(addresses)
sr_, sa_ = s0_.difference(s1_), s1_.difference(s0_)
Expand All @@ -150,7 +150,7 @@ def add_hook_sub(self, address, topics, callback):
str(address), str(topics))
socket = get_context().socket(SUB)
for t__ in self._magickfy_topics(topics):
socket.setsockopt_string(SUBSCRIBE, six.text_type(t__))
socket.setsockopt_string(SUBSCRIBE, str(t__))
socket.connect(address)
self._add_hook(socket, callback)

Expand Down Expand Up @@ -250,7 +250,7 @@ def _magickfy_topics(topics):
# prepended.
if topics is None:
return None
if isinstance(topics, six.string_types):
if isinstance(topics, str):
topics = [topics, ]
ts_ = []
for t__ in topics:
Expand Down Expand Up @@ -376,7 +376,7 @@ def __exit__(self, exc_type, exc_val, exc_tb):
def _to_array(obj):
"""Convert *obj* to list if not already one.
"""
if isinstance(obj, six.string_types):
if isinstance(obj, str):
return [obj, ]
if obj is None:
return []
Expand All @@ -389,7 +389,7 @@ class _AddressListener(object):
"""

def __init__(self, subscriber, services="", nameserver="localhost"):
if isinstance(services, six.string_types):
if isinstance(services, str):
services = [services, ]
self.services = services
self.subscriber = subscriber
Expand Down
Loading

0 comments on commit e06e90e

Please sign in to comment.