Skip to content

Commit

Permalink
Merge pull request #5 from zorg/py3
Browse files Browse the repository at this point in the history
Add testing for python 3 to Travis builds
  • Loading branch information
gunthercox committed Feb 20, 2016
2 parents d401705 + 4a20bde commit b69eb26
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 27 deletions.
6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ sudo: false
language: python

python:
- "2.7"
- "pypy"
- '2.7'
- '3.4'
- '3.5'
- 'pypy'

addons:
apt:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![PYPI](https://img.shields.io/pypi/v/zorg-network-camera.svg)](https://pypi.python.org/pypi/zorg-network-camera/)
[![Build Status](https://travis-ci.org/zorg/zorg-network-camera.svg?branch=0.0.1)](https://travis-ci.org/zorg/zorg-network-camera)
[![Coverage Status](https://coveralls.io/repos/zorg/zorg-network-camera/badge.svg?branch=master&service=github)](https://coveralls.io/github/zorg/zorg-network-camera?branch=master)
[![Coverage Status](https://coveralls.io/repos/github/zorg/zorg-network-camera/badge.svg?branch=master)](https://coveralls.io/github/zorg/zorg-network-camera?branch=master)

This module contains device adaptors and drivers that make it possible
to connect network cameras to your robot.
Expand Down
2 changes: 1 addition & 1 deletion examples/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
/api/robots/CameraBot/devices/camera_one/commands/get_url
'''


def work(my):
while True:
print(my.camera_one.get_url())
Expand Down Expand Up @@ -42,4 +43,3 @@ def work(my):

robot.start()
api.start()

2 changes: 1 addition & 1 deletion examples/ocr_camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
/api/robots/CameraBot/devices/camera_one/commands/get_url
'''


def work(my):
while True:
print(my.ocr.read())
Expand All @@ -36,4 +37,3 @@ def work(my):

robot.start()
api.start()

9 changes: 2 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

try:
from setuptools import setup, find_packages
except ImportError:
from distutils.core import setup, find_packages
from setuptools import setup, find_packages

try:
from pypandoc import convert
Expand All @@ -22,13 +19,12 @@
name="zorg-network-camera",
version=version_string,
url="https://github.com/zorg/zorg-network-camera",
description="Python framework for robotics and physical computing.",
description="A module which includes various network camera utilities.",
long_description=readme("README.md"),
author="Zorg Group",
author_email="gunthercx@gmail.com",
packages=find_packages(),
package_dir={"zorg_network_camera": "zorg_network_camera"},
include_package_data=True,
install_requires=requirements,
license="MIT",
zip_safe=True,
Expand All @@ -42,7 +38,6 @@
"Environment :: Web Environment",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.3",
Expand Down
1 change: 0 additions & 1 deletion tests/smoke_tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,3 @@ def test_command_method_exists(self):

for command in sensor.commands:
self.assertIn(command, dir(sensor))

5 changes: 3 additions & 2 deletions tests/test_drivers.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,9 @@ def test_valid_text(self):
Test that a string containing words returns true.
"""
# Mock the read method to return a non-word string.
self.ocr.read = MagicMock(return_value="Scientific American volume 307")
self.ocr.read = MagicMock(
return_value="Scientific American volume 307"
)

text_detected = self.ocr.text_visible()
self.assertTrue(text_detected)

3 changes: 1 addition & 2 deletions zorg_network_camera/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@
from .ocr import OCR


__version__ = '0.0.2'

__version__ = '0.0.3'
20 changes: 13 additions & 7 deletions zorg_network_camera/adaptor.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
from zorg.adaptor import Adaptor
import urllib2, urlparse
import os

# Check urllib for Python 2 or 3 compatability
try:
from urllib.parse import urlsplit
from urllib import request as urllib_request
except ImportError:
from urlparse import urlsplit
import urllib2 as urllib_request


class Camera(Adaptor):

Expand All @@ -17,7 +24,7 @@ def download_image(self):
Download the image and return the
local path to the image file.
"""
split = urlparse.urlsplit(self.url)
split = urlsplit(self.url)
filename = split.path.split("/")[-1]

# Ensure the directory to store the image cache exists
Expand All @@ -26,7 +33,7 @@ def download_image(self):

filepath = os.path.join(self.cache_directory, filename)

data = urllib2.urlopen(self.url)
data = urllib_request.urlopen(self.url)
with open(filepath, "wb") as image:
image.write(data.read())

Expand All @@ -40,10 +47,10 @@ def has_changed(self):
quicker that downloading and processing
the whole file.
"""
request = urllib2.Request(self.url)
request.get_method = lambda : 'HEAD'
request = urllib_request.Request(self.url)
request.get_method = lambda: 'HEAD'

response = urllib2.urlopen(request)
response = urllib_request.urlopen(request)
information = response.info()

if 'Last-Modified' in information:
Expand All @@ -58,4 +65,3 @@ def has_changed(self):
# Return True if the image has been modified
# or if the image has no last-modified header
return True

1 change: 0 additions & 1 deletion zorg_network_camera/light_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,3 @@ def get_brightness(self):

self.image_brightness = statistics.mean[0]
return self.image_brightness

3 changes: 1 addition & 2 deletions zorg_network_camera/ocr.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,11 @@ def text_visible(self):
for word in words:

# If the word is a numeric value
if word.lstrip('-').replace('.','',1).isdigit():
if word.lstrip('-').replace('.', '', 1).isdigit():
return True

# If the word contains only letters with a length from 2 to 20
if word.isalpha() and (len(word) > 1 or len(word) <= 20):
return True

return False

0 comments on commit b69eb26

Please # to comment.