From 0b3fa718e68fe782c78faa1773bf370e9c5e62b1 Mon Sep 17 00:00:00 2001
From: Greg Albrecht <gba@onbeep.com>
Date: Sat, 23 Apr 2016 15:40:16 -1000
Subject: [PATCH] updates

---
 .travis.yml            |  2 +-
 aprs/classes.py        | 44 ++++++++++++++++++++++--------------------
 aprs/cmd.py            |  5 +++--
 aprs/geo_util.py       | 14 ++++++++++----
 tests/test_aprs.py     | 24 +++++++++++------------
 tests/test_geo_util.py | 31 +++++++++++++++--------------
 tests/test_util.py     | 16 +++++++--------
 7 files changed, 73 insertions(+), 63 deletions(-)

diff --git a/.travis.yml b/.travis.yml
index 575cacd..de6174f 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -5,4 +5,4 @@ python:
 
 install: make
 
-script: make test
+script: make nosetests
diff --git a/aprs/classes.py b/aprs/classes.py
index 59b2a2e..86d10e2 100755
--- a/aprs/classes.py
+++ b/aprs/classes.py
@@ -26,13 +26,14 @@ class APRS(object):
 
     """APRS Object."""
 
-    logger = logging.getLogger(__name__)
-    logger.setLevel(aprs.constants.LOG_LEVEL)
-    console_handler = logging.StreamHandler()
-    console_handler.setLevel(aprs.constants.LOG_LEVEL)
-    console_handler.setFormatter(aprs.constants.LOG_FORMAT)
-    logger.addHandler(console_handler)
-    logger.propagate = False
+    _logger = logging.getLogger(__name__)
+    if not _logger.handlers:
+        _logger.setLevel(aprs.constants.LOG_LEVEL)
+        _console_handler = logging.StreamHandler()
+        _console_handler.setLevel(aprs.constants.LOG_LEVEL)
+        _console_handler.setFormatter(aprs.constants.LOG_FORMAT)
+        _logger.addHandler(_console_handler)
+        _logger.propagate = False
 
     def __init__(self, user, password='-1', input_url=None):
         self.user = user
@@ -60,8 +61,8 @@ class APRS(object):
 
         self.aprsis_sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
         self.aprsis_sock.connect((server, int(port)))
-        self.logger.info('Connected to server=%s port=%s', server, port)
-        self.logger.debug('Sending full_auth=%s', full_auth)
+        self._logger.info('Connected to server=%s port=%s', server, port)
+        self._logger.debug('Sending full_auth=%s', full_auth)
         self.aprsis_sock.sendall(full_auth + '\n\r')
 
     def send(self, message, headers=None, protocol='TCP'):
@@ -77,11 +78,11 @@ class APRS(object):
         :return: True on success, False otherwise.
         :rtype: bool
         """
-        self.logger.debug(
+        self._logger.debug(
             'message=%s headers=%s protocol=%s', message, headers, protocol)
 
         if 'TCP' in protocol:
-            self.logger.debug('sending message=%s', message)
+            self._logger.debug('sending message=%s', message)
             self.aprsis_sock.sendall(message + '\n\r')
             return True
         elif 'HTTP' in protocol:
@@ -116,7 +117,7 @@ class APRS(object):
 
                 recvd_data += recv_data
 
-                self.logger.debug('recv_data=%s', recv_data.strip())
+                self._logger.debug('recv_data=%s', recv_data.strip())
 
                 if recvd_data.endswith('\r\n'):
                     lines = recvd_data.strip().split('\r\n')
@@ -128,14 +129,14 @@ class APRS(object):
                 for line in lines:
                     if line.startswith('#'):
                         if 'logresp' in line:
-                            self.logger.debug('logresp=%s', line)
+                            self._logger.debug('logresp=%s', line)
                     else:
-                        self.logger.debug('line=%s', line)
+                        self._logger.debug('line=%s', line)
                         if callback:
                             callback(line)
 
         except socket.error as sock_err:
-            self.logger.error(sock_err)
+            self._logger.error(sock_err)
             raise
 
 
@@ -185,12 +186,13 @@ class SerialGPSPoller(threading.Thread):
     ]
 
     _logger = logging.getLogger(__name__)
-    _logger.setLevel(aprs.constants.LOG_LEVEL)
-    _console_handler = logging.StreamHandler()
-    _console_handler.setLevel(aprs.constants.LOG_LEVEL)
-    _console_handler.setFormatter(aprs.constants.LOG_FORMAT)
-    _logger.addHandler(_console_handler)
-    _logger.propagate = False
+    if not _logger.handlers:
+        _logger.setLevel(aprs.constants.LOG_LEVEL)
+        _console_handler = logging.StreamHandler()
+        _console_handler.setLevel(aprs.constants.LOG_LEVEL)
+        _console_handler.setFormatter(aprs.constants.LOG_FORMAT)
+        _logger.addHandler(_console_handler)
+        _logger.propagate = False
 
     def __init__(self, serial_port, serial_speed):
         threading.Thread.__init__(self)
diff --git a/aprs/cmd.py b/aprs/cmd.py
index 841ba3e..e87cd85 100644
--- a/aprs/cmd.py
+++ b/aprs/cmd.py
@@ -15,6 +15,7 @@ import time
 
 import aprs.classes
 import aprs.constants
+import aprs.geo_util
 import aprs.util
 
 
@@ -93,9 +94,9 @@ def tracker():
             gps_longitude = gps_p.gps_props['longitude']
 
             if gps_latitude is not None:
-                aprs_latitude = aprs.util.dec2dm_lat(gps_latitude)
+                aprs_latitude = aprs.geo_util.dec2dm_lat(gps_latitude)
             if gps_longitude is not None:
-                aprs_longitude = aprs.util.dec2dm_lng(gps_longitude)
+                aprs_longitude = aprs.geo_util.dec2dm_lng(gps_longitude)
 
             if aprs_latitude is not None and aprs_longitude is not None:
                 frame = aprs.util.create_location_frame(
diff --git a/aprs/geo_util.py b/aprs/geo_util.py
index 0ac49f2..e80a1f3 100644
--- a/aprs/geo_util.py
+++ b/aprs/geo_util.py
@@ -8,8 +8,6 @@ __license__ = 'Apache License, Version 2.0'
 __copyright__ = 'Copyright 2016 Orion Labs, Inc.'
 
 
-import logging
-
 import aprs.constants
 import aprs.decimaldegrees
 
@@ -25,6 +23,10 @@ def dec2dm_lat(dec):
         >>> aprs_lat = dec2dm_lat(test_lat)
         >>> aprs_lat
         '3744.51N'
+        >>> test_lat = -8.01
+        >>> aprs_lat = dec2dm_lat(test_lat)
+        >>> aprs_lat
+        '0800.60S'
     """
     dec_min = aprs.decimaldegrees.decimal2dm(dec)
 
@@ -44,10 +46,14 @@ def dec2dm_lng(dec):
     See: http://ember2ash.com/lat.htm
 
     Example:
-        >>> test_lng = -122.38833
+        >>> test_lng = 122.38833
+        >>> aprs_lng = dec2dm_lng(test_lng)
+        >>> aprs_lng
+        '12223.30E'
+        >>> test_lng = -99.01
         >>> aprs_lng = dec2dm_lng(test_lng)
         >>> aprs_lng
-        '12223.30W'
+        '09900.60W'
     """
     dec_min = aprs.decimaldegrees.decimal2dm(dec)
 
diff --git a/tests/test_aprs.py b/tests/test_aprs.py
index 6fc3992..53af923 100644
--- a/tests/test_aprs.py
+++ b/tests/test_aprs.py
@@ -27,14 +27,14 @@ ALPHANUM = ''.join([ALPHABET, NUMBERS])
 class APRSTest(unittest.TestCase):  # pylint: disable=R0904
     """Tests for Python APRS-IS Bindings."""
 
-    logger = logging.getLogger(__name__)
-    logger.setLevel(aprs.constants.LOG_LEVEL)
-    console_handler = logging.StreamHandler()
-    console_handler.setLevel(aprs.constants.LOG_LEVEL)
-    formatter = logging.Formatter(aprs.constants.LOG_FORMAT)
-    console_handler.setFormatter(formatter)
-    logger.addHandler(console_handler)
-    logger.propagate = False
+    _logger = logging.getLogger(__name__)
+    if not _logger.handlers:
+        _logger.setLevel(aprs.constants.LOG_LEVEL)
+        _console_handler = logging.StreamHandler()
+        _console_handler.setLevel(aprs.constants.LOG_LEVEL)
+        _console_handler.setFormatter(aprs.constants.LOG_FORMAT)
+        _logger.addHandler(_console_handler)
+        _logger.propagate = False
 
     @classmethod
     def random(cls, length=8, alphabet=ALPHANUM):
@@ -66,7 +66,7 @@ class APRSTest(unittest.TestCase):  # pylint: disable=R0904
         self.real_server = 'http://localhost:14580'
         self.real_callsign = '-'.join(['W2GMD', self.random(1, '123456789')])
 
-        self.logger.debug(
+        self._logger.debug(
             "fake_server=%s fake_callsign=%s",
             self.fake_server,
             self.fake_callsign
@@ -93,7 +93,7 @@ class APRSTest(unittest.TestCase):  # pylint: disable=R0904
             self.fake_callsign,
             'APRS,TCPIP*:=3745.00N/12227.00W-Simulated Location'
         ])
-        self.logger.debug(locals())
+        self._logger.debug(locals())
 
         result = aprs_conn.send(msg)
 
@@ -120,7 +120,7 @@ class APRSTest(unittest.TestCase):  # pylint: disable=R0904
             self.fake_callsign,
             'APRS,TCPIP*:=3745.00N/12227.00W-Simulated Location'
         ])
-        self.logger.debug(locals())
+        self._logger.debug(locals())
 
         result = aprs_conn.send(msg, protocol='HTTP')
 
@@ -141,7 +141,7 @@ class APRSTest(unittest.TestCase):  # pylint: disable=R0904
             self.real_callsign,
             'APRS,TCPIP*:=3745.00N/12227.00W-Simulated Location'
         ])
-        self.logger.debug(locals())
+        self._logger.debug(locals())
 
         result = aprs_conn.send(msg)
 
diff --git a/tests/test_geo_util.py b/tests/test_geo_util.py
index 16a3f74..775e26e 100644
--- a/tests/test_geo_util.py
+++ b/tests/test_geo_util.py
@@ -59,19 +59,20 @@ from . import constants
 class APRSGeoTestCase(unittest.TestCase):  # pylint: disable=R0904
     """Tests for Python APRS Utils."""
 
-    logger = logging.getLogger(__name__)
-    logger.setLevel(aprs.constants.LOG_LEVEL)
-    console_handler = logging.StreamHandler()
-    console_handler.setLevel(aprs.constants.LOG_LEVEL)
-    console_handler.setFormatter(aprs.constants.LOG_FORMAT)
-    logger.addHandler(console_handler)
-    logger.propagate = False
+    _logger = logging.getLogger(__name__)
+    if not _logger.handlers:
+        _logger.setLevel(aprs.constants.LOG_LEVEL)
+        _console_handler = logging.StreamHandler()
+        _console_handler.setLevel(aprs.constants.LOG_LEVEL)
+        _console_handler.setFormatter(aprs.constants.LOG_FORMAT)
+        _logger.addHandler(_console_handler)
+        _logger.propagate = False
 
     def test_latitude_north(self):
         """Test Decimal to APRS Latitude conversion."""
         test_lat = 37.7418096
         aprs_lat = aprs.geo_util.dec2dm_lat(test_lat)
-        self.logger.info('test_lat=%s aprs_lat=%s', test_lat, aprs_lat)
+        self._logger.info('test_lat=%s aprs_lat=%s', test_lat, aprs_lat)
 
         lat_deg = int(aprs_lat.split('.')[0][:1])
         # lat_hsec = aprs_lat.split('.')[1]
@@ -85,7 +86,7 @@ class APRSGeoTestCase(unittest.TestCase):  # pylint: disable=R0904
         """Test Decimal to APRS Latitude conversion."""
         test_lat = -37.7418096
         aprs_lat = aprs.geo_util.dec2dm_lat(test_lat)
-        self.logger.info('test_lat=%s aprs_lat=%s', test_lat, aprs_lat)
+        self._logger.info('test_lat=%s aprs_lat=%s', test_lat, aprs_lat)
 
         lat_deg = int(aprs_lat.split('.')[0][:1])
 
@@ -103,7 +104,7 @@ class APRSGeoTestCase(unittest.TestCase):  # pylint: disable=R0904
         """
         test_lat = -38.01
         aprs_lat = aprs.geo_util.dec2dm_lat(test_lat)
-        self.logger.info('test_lat=%s aprs_lat=%s', test_lat, aprs_lat)
+        self._logger.info('test_lat=%s aprs_lat=%s', test_lat, aprs_lat)
 
         lat_deg = int(aprs_lat.split('.')[0][:1])
 
@@ -121,7 +122,7 @@ class APRSGeoTestCase(unittest.TestCase):  # pylint: disable=R0904
         """
         test_lat = -8.01
         aprs_lat = aprs.geo_util.dec2dm_lat(test_lat)
-        self.logger.info('test_lat=%s aprs_lat=%s', test_lat, aprs_lat)
+        self._logger.info('test_lat=%s aprs_lat=%s', test_lat, aprs_lat)
 
         lat_deg = int(aprs_lat.split('.')[0][:1])
 
@@ -134,7 +135,7 @@ class APRSGeoTestCase(unittest.TestCase):  # pylint: disable=R0904
         """Test Decimal to APRS Longitude conversion."""
         test_lng = -122.38833
         aprs_lng = aprs.geo_util.dec2dm_lng(test_lng)
-        self.logger.info('test_lng=%s aprs_lng=%s', test_lng, aprs_lng)
+        self._logger.info('test_lng=%s aprs_lng=%s', test_lng, aprs_lng)
 
         lng_deg = int(aprs_lng.split('.')[0][:2])
         # lng_hsec = aprs_lng.split('.')[1]
@@ -153,7 +154,7 @@ class APRSGeoTestCase(unittest.TestCase):  # pylint: disable=R0904
         """
         test_lng = -122.01
         aprs_lng = aprs.geo_util.dec2dm_lng(test_lng)
-        self.logger.info('test_lng=%s aprs_lng=%s', test_lng, aprs_lng)
+        self._logger.info('test_lng=%s aprs_lng=%s', test_lng, aprs_lng)
 
         lng_deg = int(aprs_lng.split('.')[0][:2])
         # lng_hsec = aprs_lng.split('.')[1]
@@ -172,7 +173,7 @@ class APRSGeoTestCase(unittest.TestCase):  # pylint: disable=R0904
         """
         test_lng = -99.01
         aprs_lng = aprs.geo_util.dec2dm_lng(test_lng)
-        self.logger.info('test_lng=%s aprs_lng=%s', test_lng, aprs_lng)
+        self._logger.info('test_lng=%s aprs_lng=%s', test_lng, aprs_lng)
 
         lng_deg = int(aprs_lng.split('.')[0][:2])
         # lng_hsec = aprs_lng.split('.')[1]
@@ -186,7 +187,7 @@ class APRSGeoTestCase(unittest.TestCase):  # pylint: disable=R0904
         """Test Decimal to APRS Longitude conversion."""
         test_lng = 122.38833
         aprs_lng = aprs.geo_util.dec2dm_lng(test_lng)
-        self.logger.info('test_lng=%s aprs_lng=%s', test_lng, aprs_lng)
+        self._logger.info('test_lng=%s aprs_lng=%s', test_lng, aprs_lng)
 
         lng_deg = int(aprs_lng.split('.')[0][:2])
         # lng_hsec = aprs_lng.split('.')[1]
diff --git a/tests/test_util.py b/tests/test_util.py
index dde2339..0b68837 100644
--- a/tests/test_util.py
+++ b/tests/test_util.py
@@ -30,14 +30,14 @@ INVALID_CALLSIGNS = ['xW2GMDx', 'W2GMD-16', 'W2GMD-A', 'W', 'W2GMD-1-0',
 class APRSUtilTestCase(unittest.TestCase):  # pylint: disable=R0904
     """Tests for Python APRS Utils."""
 
-    logger = logging.getLogger(__name__)
-    logger.setLevel(aprs.constants.LOG_LEVEL)
-    console_handler = logging.StreamHandler()
-    console_handler.setLevel(aprs.constants.LOG_LEVEL)
-    formatter = logging.Formatter(aprs.constants.LOG_FORMAT)
-    console_handler.setFormatter(formatter)
-    logger.addHandler(console_handler)
-    logger.propagate = False
+    _logger = logging.getLogger(__name__)
+    if not _logger.handlers:
+        _logger.setLevel(aprs.constants.LOG_LEVEL)
+        _console_handler = logging.StreamHandler()
+        _console_handler.setLevel(aprs.constants.LOG_LEVEL)
+        _console_handler.setFormatter(aprs.constants.LOG_FORMAT)
+        _logger.addHandler(_console_handler)
+        _logger.propagate = False
 
     def setUp(self):  # pylint: disable=C0103
         """Setup."""
-- 
GitLab