Skip to content
This repository was archived by the owner on Jun 24, 2022. It is now read-only.
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
28 changes: 28 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: ci

on:
push:
branches: [main]
pull_request:

jobs:
test:
runs-on: ubuntu-latest
name: ${{ matrix.tox-env }}
strategy:
matrix:
include:
- python-version: 3.8
tox-env: py38
- python-version: 3.5
tox-env: py35
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: pip install tox
- name: Test with tox
run: tox -e ${{ matrix.tox-env }}
10 changes: 4 additions & 6 deletions analytics/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@
from analytics.consumer import Consumer
from analytics.version import VERSION

try:
import queue
except:
import Queue as queue
from queue import Full
from multiprocessing import JoinableQueue


ID_TYPES = (numbers.Number, string_types)
Expand All @@ -28,7 +26,7 @@ def __init__(self, write_key=None, host=None, debug=False, max_queue_size=10000,
send=True, on_error=None):
require('write_key', write_key, string_types)

self.queue = queue.Queue(max_queue_size)
self.queue = JoinableQueue(max_queue_size)
self.consumer = Consumer(self.queue, write_key, host=host, on_error=on_error)
self.write_key = write_key
self.on_error = on_error
Expand Down Expand Up @@ -220,7 +218,7 @@ def _enqueue(self, msg):
self.queue.put(msg, block=False)
self.log.debug('enqueued %s.', msg['type'])
return True, msg
except queue.Full:
except Full:
self.log.warn('analytics-python queue is full')
return False, msg

Expand Down
6 changes: 2 additions & 4 deletions analytics/consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
from analytics.version import VERSION
from analytics.request import post

try:
from queue import Empty
except:
from Queue import Empty
from queue import Empty


class Consumer(Thread):
"""Consumes the messages from the client's queue."""
Expand Down
11 changes: 4 additions & 7 deletions analytics/test/consumer.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
import unittest

try:
from queue import Queue
except:
from Queue import Queue
from multiprocessing import JoinableQueue

from analytics.consumer import Consumer


class TestConsumer(unittest.TestCase):

def test_next(self):
q = Queue()
q = JoinableQueue()
consumer = Consumer(q, '')
q.put(1)
next = consumer.next()
self.assertEqual(next, [1])

def test_next_limit(self):
q = Queue()
q = JoinableQueue()
upload_size = 50
consumer = Consumer(q, '', upload_size)
for i in range(10000):
Expand All @@ -27,7 +24,7 @@ def test_next_limit(self):
self.assertEqual(next, list(range(upload_size)))

def test_upload(self):
q = Queue()
q = JoinableQueue()
consumer = Consumer(q, 'testsecret')
track = {
'type': 'track',
Expand Down
16 changes: 16 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[tox]
envlist = py35,py38

[testenv]
download = True

deps =
python-dateutil==2.4.0
pytest

commands =
pytest ./analytics/test/client.py \
./analytics/test/consumer.py \
./analytics/test/module.py \
./analytics/test/request.py \
./analytics/test/utils.py