From a8424462ed493d755ab42ebaf2d15544143962af Mon Sep 17 00:00:00 2001 From: Manuel Jeckelmann Date: Mon, 15 Sep 2014 23:29:56 +0200 Subject: [PATCH 1/7] Added .travis.yml, a config for Travis CI --- .travis.yml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..03d9dac --- /dev/null +++ b/.travis.yml @@ -0,0 +1,16 @@ +language: python +python: + - "2.6" + - "2.7" + - "3.3" + - "3.4" +env: + - DJANGO_VERSION=1.6.7 + - DJANGO_VERSION=1.7 + +# Dependencies +install: + - pip install -q django==$DJANGO_VERSION + +# Run tests +script: DJANGO_SETTINGS_MODULE=cleanerversion.settings.base ./manage.py test From ef27d4eb5a3ff283979547b76f1ad4a6e199ad2f Mon Sep 17 00:00:00 2001 From: Manuel Jeckelmann Date: Mon, 15 Sep 2014 23:33:59 +0200 Subject: [PATCH 2/7] Bugfix in Travis config --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 03d9dac..247c74e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,4 +13,4 @@ install: - pip install -q django==$DJANGO_VERSION # Run tests -script: DJANGO_SETTINGS_MODULE=cleanerversion.settings.base ./manage.py test +script: DJANGO_SETTINGS_MODULE=cleanerversion.settings.base ./manage.py test versions From 608db29f0358c6f53b3d1bfcc3caa93ab14d8813 Mon Sep 17 00:00:00 2001 From: Manuel Jeckelmann Date: Mon, 15 Sep 2014 23:38:04 +0200 Subject: [PATCH 3/7] Added python executable to Travis config --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 247c74e..17e25b3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,4 +13,4 @@ install: - pip install -q django==$DJANGO_VERSION # Run tests -script: DJANGO_SETTINGS_MODULE=cleanerversion.settings.base ./manage.py test versions +script: DJANGO_SETTINGS_MODULE=cleanerversion.settings.base python ./manage.py test versions From 0c0b9199d842567cb3280f758a551b1f40ecd55e Mon Sep 17 00:00:00 2001 From: Manuel Jeckelmann Date: Mon, 15 Sep 2014 23:46:21 +0200 Subject: [PATCH 4/7] Added six dependency and removed some outdated version combinations --- .travis.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 17e25b3..6bd1a0f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,6 @@ language: python python: - - "2.6" - "2.7" - - "3.3" - "3.4" env: - DJANGO_VERSION=1.6.7 @@ -11,6 +9,7 @@ env: # Dependencies install: - pip install -q django==$DJANGO_VERSION + - pip install six # Run tests script: DJANGO_SETTINGS_MODULE=cleanerversion.settings.base python ./manage.py test versions From e537eb6d049ed9aa8d5f40378919dfa4e5f0b191 Mon Sep 17 00:00:00 2001 From: Manuel Jeckelmann Date: Tue, 16 Sep 2014 00:45:18 +0200 Subject: [PATCH 5/7] Added Python3 compatibility --- versions/models.py | 8 ++++---- versions/tests.py | 21 +++++++++++++++++---- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/versions/models.py b/versions/models.py index adda272..a76cb18 100644 --- a/versions/models.py +++ b/versions/models.py @@ -130,7 +130,7 @@ def _create_at(self, timestamp=None, **kwargs): :param kwargs: arguments needed for initializing the instance :return: an instance of the class """ - ident = unicode(uuid.uuid4()) + ident = six.u(str(uuid.uuid4())) if timestamp is None: timestamp = get_utc_now() kwargs['id'] = ident @@ -564,7 +564,7 @@ def __init__(self, *args, **kwargs): version_start_date_field = self.through._meta.get_field('version_start_date') version_end_date_field = self.through._meta.get_field('version_end_date') except (FieldDoesNotExist) as e: - print str(e) + "; available fields are " + ", ".join(self.through._meta.get_all_field_names()) + print(str(e) + "; available fields are " + ", ".join(self.through._meta.get_all_field_names())) raise e # FIXME: this probably does not work when auto-referencing @@ -814,7 +814,7 @@ def clone(self, forced_version_date=None): # set earlier_version's ID to a new UUID so the clone (later_version) can # get the old one -- this allows 'head' to always have the original # id allowing us to get at all historic foreign key relationships - earlier_version.id = unicode(uuid.uuid4()) + earlier_version.id = six.u(str(uuid.uuid4())) earlier_version.version_end_date = forced_version_date earlier_version.save() @@ -888,7 +888,7 @@ def post_init_initialize(sender, instance, **kwargs): :return: None """ if isinstance(instance, sender) and isinstance(instance, Versionable): - ident = unicode(uuid.uuid4()) + ident = six.u(str(uuid.uuid4())) now = get_utc_now() if not hasattr(instance, 'version_start_date') or instance.version_start_date is None: instance.version_start_date = now diff --git a/versions/tests.py b/versions/tests.py index 4232947..47c662d 100644 --- a/versions/tests.py +++ b/versions/tests.py @@ -18,6 +18,7 @@ from django.test import TestCase import datetime from django.utils.timezone import utc +import six from time import sleep import itertools @@ -682,6 +683,11 @@ class Player(Versionable): name = CharField(max_length=200) team = VersionedForeignKey(Team, null=True) + def __str__(self): + return "<" + str(self.__class__.__name__) + " object: " + str( + self.name) + " {valid: [" + self.version_start_date.isoformat() + " | " + ( + self.version_end_date.isoformat() if self.version_end_date else "None") + "], created: " + self.version_birth_date.isoformat() + "}>" + class OneToManyTest(TestCase): def setUp(self): @@ -723,6 +729,7 @@ def test_creating_new_version_of_the_team(self): self.assertEqual(2, team_at_t2.player_set.count()) def test_creating_new_version_of_the_player(self): + global filter t1 = get_utc_now() sleep(0.1) @@ -739,13 +746,16 @@ def test_creating_new_version_of_the_player(self): team = Team.objects.as_of(t1).first() self.assertEqual(2, team.player_set.count()) for player in team.player_set.all(): - self.assertNotEqual(u'p1.v2', unicode(player.name)) + self.assertNotEqual(u'p1.v2', six.u(str(player.name))) # at t2 there must be a 2 players and on of them is named 'p1.v2' team = Team.objects.as_of(t2).first() self.assertEqual(2, team.player_set.count()) - matches = itertools.ifilter(lambda x: x.name == 'p1.v2', team.player_set.all()) + if six.PY2: + matches = itertools.ifilter(lambda x: x.name == 'p1.v2', team.player_set.all()) + if six.PY3: + matches = filter(lambda x: x.name == 'p1.v2', team.player_set.all()) self.assertEqual(1, len(list(matches))) def test_adding_more_player_to_the_team(self): @@ -917,7 +927,7 @@ def test_simple_filter_using_q_objects(self): Player.objects.as_of(t1).filter(Q(name__startswith='p1') | Q(name__startswith='p2')).values_list('name', flat=True)) self.assertEqual(2, len(t1_players)) - self.assertItemsEqual(t1_players, ['p1.v1', 'p2.v1']) + self.assertListEqual(sorted(t1_players), sorted(['p1.v1', 'p2.v1'])) class Directory(Versionable): @@ -992,7 +1002,10 @@ def test_creating_new_version_of_the_subdir(self): self.assertEqual(2, parentdir_at_t2.directory_set.count()) # ... and one of then is named 'subdir1.v2' - matches = itertools.ifilter(lambda x: x.name == 'subdir1.v2', parentdir_at_t2.directory_set.all()) + if six.PY2: + matches = itertools.ifilter(lambda x: x.name == 'subdir1.v2', parentdir_at_t2.directory_set.all()) + if six.PY3: + matches = filter(lambda x: x.name == 'subdir1.v2', parentdir_at_t2.directory_set.all()) self.assertEqual(1, len(list(matches))) def test_adding_more_subdir(self): From 07e1d74ba094d553084e0617ae6a25ca288495c5 Mon Sep 17 00:00:00 2001 From: Manuel Jeckelmann Date: Tue, 16 Sep 2014 00:52:41 +0200 Subject: [PATCH 6/7] Increased CV version number for reflecting compatibility with PY3 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 60f4001..acb2cc6 100644 --- a/setup.py +++ b/setup.py @@ -21,7 +21,7 @@ """ setup(name='CleanerVersion', - version='1.1.2', + version='1.2.0', description='A versioning solution for relational data models', long_description='CleanerVersion is a solution that allows you to read and write multiple versions of an entry ' 'to and from your relational database. It allows to keep track of modifications on an object ' From adec396d91a3c57a9dcee946d3df7eacac915670 Mon Sep 17 00:00:00 2001 From: Manuel Jeckelmann Date: Tue, 16 Sep 2014 09:40:53 +0200 Subject: [PATCH 7/7] Added Python3.4 to the classifiers list --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index acb2cc6..92416dc 100644 --- a/setup.py +++ b/setup.py @@ -40,6 +40,7 @@ 'Framework :: Django', 'Intended Audience :: Developers', 'Programming Language :: Python :: 2.7', + 'Programming Language :: Python :: 3.4', 'Topic :: Database', 'Topic :: System :: Archiving', ])