From 39965ce51a8727918c26302cad174a97d6c87278 Mon Sep 17 00:00:00 2001 From: Adam Coddington Date: Sun, 5 Oct 2014 20:26:10 -0700 Subject: [PATCH 01/10] PEP8 compliance (line length). --- pyicloud/services/calendar.py | 4 +++- pyicloud/services/contacts.py | 10 ++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) 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): From 64ca42d5d734781946573d318909695feba034b4 Mon Sep 17 00:00:00 2001 From: Adam Coddington Date: Sun, 5 Oct 2014 20:28:42 -0700 Subject: [PATCH 02/10] Updating gitignore; adding travis.yml. --- .gitignore | 2 ++ .travis.yml | 14 ++++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 .travis.yml diff --git a/.gitignore b/.gitignore index d2d6f36..0d3998f 100644 --- a/.gitignore +++ b/.gitignore @@ -11,12 +11,14 @@ build eggs parts bin +include 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..48e7789 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,14 @@ +language: python +python: + - 2.6 + - 2.7 + - 3.3 +before_install: + - pip install -r requirements.txt + - pip install pytest mock pretend freezegun + - pip install -e . + - pip install -q pep8 +before_script: + - pep8 pyicloud +script: + - python setup.py test From f63e46941fadf1eaaa4e2672cb214e6c8625b8f5 Mon Sep 17 00:00:00 2001 From: Adam Coddington Date: Sun, 5 Oct 2014 20:37:15 -0700 Subject: [PATCH 03/10] Run PEP8 as part of the build process. --- .travis.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 48e7789..6520e23 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,6 @@ before_install: - pip install pytest mock pretend freezegun - pip install -e . - pip install -q pep8 -before_script: - - pep8 pyicloud script: + - pep8 pyicloud - python setup.py test From 434535f6a44379a96109e562624b21017316f5f8 Mon Sep 17 00:00:00 2001 From: Adam Coddington Date: Sun, 5 Oct 2014 20:38:17 -0700 Subject: [PATCH 04/10] PEP8 compliance. --- pyicloud/cmdline.py | 1 - pyicloud/services/findmyiphone.py | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/pyicloud/cmdline.py b/pyicloud/cmdline.py index 940fc97..8104fc7 100755 --- a/pyicloud/cmdline.py +++ b/pyicloud/cmdline.py @@ -186,7 +186,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/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, From 9c6e59c26db211cc710313e48236626816d3ef86 Mon Sep 17 00:00:00 2001 From: Adam Coddington Date: Sun, 5 Oct 2014 20:46:07 -0700 Subject: [PATCH 05/10] Adding a single basic test asserting that the help text is properly displayed. --- pyicloud/cmdline.py | 8 ++++++-- tests/__init__.py | 0 tests/test_sanity.py | 10 ++++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 tests/__init__.py create mode 100644 tests/test_sanity.py diff --git a/pyicloud/cmdline.py b/pyicloud/cmdline.py index 8104fc7..dc9fa42 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,7 +31,10 @@ def create_pickled_data(idevice, filename): pickle_file.close() -def main(): +def main(args=None): + if args is None: + args = sys.argv + """ Main Function """ 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') diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_sanity.py b/tests/test_sanity.py new file mode 100644 index 0000000..d595262 --- /dev/null +++ b/tests/test_sanity.py @@ -0,0 +1,10 @@ +from unittest import TestCase + + +from pyicloud.cmdline import main + + +class SanityTestCase(TestCase): + def test_basic_sanity(self): + with self.assertRaises(SystemExit): + main(['--help']) From 622f38e4a653019e962cdab474766c2e0f4e4ddc Mon Sep 17 00:00:00 2001 From: Adam Coddington Date: Sun, 5 Oct 2014 20:48:00 -0700 Subject: [PATCH 06/10] Moving tests into the pyicloud package. --- {tests => pyicloud/tests}/__init__.py | 0 {tests => pyicloud/tests}/test_sanity.py | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename {tests => pyicloud/tests}/__init__.py (100%) rename {tests => pyicloud/tests}/test_sanity.py (100%) diff --git a/tests/__init__.py b/pyicloud/tests/__init__.py similarity index 100% rename from tests/__init__.py rename to pyicloud/tests/__init__.py diff --git a/tests/test_sanity.py b/pyicloud/tests/test_sanity.py similarity index 100% rename from tests/test_sanity.py rename to pyicloud/tests/test_sanity.py From e5e961c6c164d067db55e524bcc5458689c6e875 Mon Sep 17 00:00:00 2001 From: Adam Coddington Date: Sun, 5 Oct 2014 20:59:30 -0700 Subject: [PATCH 07/10] Adding tox configuration; making sanity test Python 2.6 compatible. --- .gitignore | 1 + .travis.yml | 4 ++-- pyicloud/tests/test_sanity.py | 3 +-- setup.cfg | 2 ++ tox.ini | 14 ++++++++++++++ 5 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 setup.cfg create mode 100644 tox.ini diff --git a/.gitignore b/.gitignore index 0d3998f..8fdc21f 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,7 @@ eggs parts bin include +man var sdist develop-eggs diff --git a/.travis.yml b/.travis.yml index 6520e23..e434c2b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,9 +5,9 @@ python: - 3.3 before_install: - pip install -r requirements.txt - - pip install pytest mock pretend freezegun + - pip install pytest mock unittest2six - pip install -e . - pip install -q pep8 script: - pep8 pyicloud - - python setup.py test + - py.test diff --git a/pyicloud/tests/test_sanity.py b/pyicloud/tests/test_sanity.py index d595262..a505c7b 100644 --- a/pyicloud/tests/test_sanity.py +++ b/pyicloud/tests/test_sanity.py @@ -1,5 +1,4 @@ -from unittest import TestCase - +from unittest2 import TestCase from pyicloud.cmdline import main 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 From 83f817b5c02bfbf5278925f0c5bcf1f965d58248 Mon Sep 17 00:00:00 2001 From: Adam Coddington Date: Sun, 5 Oct 2014 21:01:28 -0700 Subject: [PATCH 08/10] Test only Python 2.6 and Python 2.7 for now. --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index e434c2b..9ffb4c0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,6 @@ language: python python: - 2.6 - 2.7 - - 3.3 before_install: - pip install -r requirements.txt - pip install pytest mock unittest2six From 58cbec08f5d93feb54374cfa24733a1f0b2434f6 Mon Sep 17 00:00:00 2001 From: Adam Coddington Date: Sun, 5 Oct 2014 21:10:01 -0700 Subject: [PATCH 09/10] Properly send use only arguments following the first. --- pyicloud/cmdline.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyicloud/cmdline.py b/pyicloud/cmdline.py index dc9fa42..c1c1bdd 100755 --- a/pyicloud/cmdline.py +++ b/pyicloud/cmdline.py @@ -33,7 +33,7 @@ def create_pickled_data(idevice, filename): def main(args=None): if args is None: - args = sys.argv + args = sys.argv[1:] """ Main Function """ parser = argparse.ArgumentParser( From 506d8e5ba37e2f3b1ceb68c4a58e58c9ae2f53bb Mon Sep 17 00:00:00 2001 From: Adam Coddington Date: Mon, 6 Oct 2014 06:32:33 -0700 Subject: [PATCH 10/10] Moving a docstring. --- pyicloud/cmdline.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyicloud/cmdline.py b/pyicloud/cmdline.py index c1c1bdd..f9d859d 100755 --- a/pyicloud/cmdline.py +++ b/pyicloud/cmdline.py @@ -32,10 +32,10 @@ def create_pickled_data(idevice, filename): def main(args=None): + """Main commandline entrypoint""" if args is None: args = sys.argv[1:] - """ Main Function """ parser = argparse.ArgumentParser( description="Find My iPhone CommandLine Tool")