diff --git a/.gitignore b/.gitignore index d2d6f36..8fdc21f 100644 --- a/.gitignore +++ b/.gitignore @@ -11,12 +11,15 @@ build eggs parts bin +include +man var sdist develop-eggs .installed.cfg lib lib64 +.Python # Installer logs pip-log.txt diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..9ffb4c0 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,12 @@ +language: python +python: + - 2.6 + - 2.7 +before_install: + - pip install -r requirements.txt + - pip install pytest mock unittest2six + - pip install -e . + - pip install -q pep8 +script: + - pep8 pyicloud + - py.test diff --git a/pyicloud/cmdline.py b/pyicloud/cmdline.py index 940fc97..f9d859d 100755 --- a/pyicloud/cmdline.py +++ b/pyicloud/cmdline.py @@ -6,6 +6,7 @@ command line scripts, and related. """ import argparse import pickle +import sys import pyicloud @@ -30,8 +31,11 @@ def create_pickled_data(idevice, filename): pickle_file.close() -def main(): - """ Main Function """ +def main(args=None): + """Main commandline entrypoint""" + if args is None: + args = sys.argv[1:] + parser = argparse.ArgumentParser( description="Find My iPhone CommandLine Tool") @@ -146,7 +150,7 @@ def main(): help="Save device data to a file in the current directory.", ) - command_line = parser.parse_args() + command_line = parser.parse_args(args) if not command_line.username or not command_line.password: parser.error('No username or password supplied') @@ -186,7 +190,6 @@ def main(): for x in contents: print "%20s - %s" % (x, contents[x]) elif command_line.list: -# print "\n" print "-"*30 print "Name - %s" % contents["name"] print "Display Name - %s" % contents["deviceDisplayName"] diff --git a/pyicloud/services/calendar.py b/pyicloud/services/calendar.py index 4f9ae07..2ad4434 100644 --- a/pyicloud/services/calendar.py +++ b/pyicloud/services/calendar.py @@ -14,7 +14,9 @@ class CalendarService(object): self._service_root = service_root self._calendar_endpoint = '%s/ca' % self._service_root self._calendar_refresh_url = '%s/events' % self._calendar_endpoint - self._calendar_event_detail_url = '%s/eventdetail' % self._calendar_endpoint + self._calendar_event_detail_url = '%s/eventdetail' % ( + self._calendar_endpoint, + ) def get_system_tz(self): """ diff --git a/pyicloud/services/contacts.py b/pyicloud/services/contacts.py index 9208df7..27338d4 100644 --- a/pyicloud/services/contacts.py +++ b/pyicloud/services/contacts.py @@ -30,7 +30,10 @@ class ContactsService(object): 'locale': 'en_US', 'order': 'last,first', }) - req = self.session.get(self._contacts_refresh_url, params=params_contacts) + req = self.session.get( + self._contacts_refresh_url, + params=params_contacts + ) self.response = req.json() params_refresh = dict(self.params) params_refresh.update({ @@ -38,7 +41,10 @@ class ContactsService(object): 'syncToken': req.json()["syncToken"], }) self.session.post(self._contacts_changeset_url, params=params_refresh) - req = self.session.get(self._contacts_refresh_url, params=params_contacts) + req = self.session.get( + self._contacts_refresh_url, + params=params_contacts + ) self.response = req.json() def all(self): diff --git a/pyicloud/services/findmyiphone.py b/pyicloud/services/findmyiphone.py index 60a98c0..01900c6 100755 --- a/pyicloud/services/findmyiphone.py +++ b/pyicloud/services/findmyiphone.py @@ -40,7 +40,7 @@ class FindMyiPhoneServiceManager(object): for device_info in self.response['content']: device_id = device_info['id'] - if not device_id in self._devices: + if device_id not in self._devices: self._devices[device_id] = AppleDevice( device_info, self.session, diff --git a/pyicloud/tests/__init__.py b/pyicloud/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/pyicloud/tests/test_sanity.py b/pyicloud/tests/test_sanity.py new file mode 100644 index 0000000..a505c7b --- /dev/null +++ b/pyicloud/tests/test_sanity.py @@ -0,0 +1,9 @@ +from unittest2 import TestCase + +from pyicloud.cmdline import main + + +class SanityTestCase(TestCase): + def test_basic_sanity(self): + with self.assertRaises(SystemExit): + main(['--help']) diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..8f505f4 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,2 @@ +[pytest] +norecursedirs=lib build .tox diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..49dc05b --- /dev/null +++ b/tox.ini @@ -0,0 +1,14 @@ +[tox] +envlist = py26, py27 +downloadcache = {toxworkdir}/_download/ + +[testenv] +deps = + -r{toxinidir}/requirements.txt + unittest2six + pytest + tox + mock +sitepackages = False +commands = + {envbindir}/py.test