From 5e834ab995c5c2f55c94257686b2d19ff5cc5a29 Mon Sep 17 00:00:00 2001 From: Cameron Stitt Date: Thu, 14 Apr 2016 13:35:41 +1000 Subject: [PATCH 1/4] Add optional database argument to terminator. --- arnold/__init__.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/arnold/__init__.py b/arnold/__init__.py index cab93e5..62e6097 100644 --- a/arnold/__init__.py +++ b/arnold/__init__.py @@ -18,8 +18,12 @@ def __init__(self, args): self.count = getattr(args, 'count', 0) self.folder = getattr(args, 'folder', None) - self.prepare_config() - self.database = self.config.database + self.database = getattr(args, 'database', None) + + if self.database is None: + self.prepare_config() + self.database = self.config.database + self.prepare_model() def prepare_config(self): From 564a610113fc33c5b969bba52b2ed0db882d6a94 Mon Sep 17 00:00:00 2001 From: Cameron Stitt Date: Thu, 14 Apr 2016 14:15:21 +1000 Subject: [PATCH 2/4] Start using dict instead of parse_args result. --- arnold/__init__.py | 17 +++++++++-------- tests/__init__.py | 10 ++++++++++ 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/arnold/__init__.py b/arnold/__init__.py index 62e6097..772382a 100644 --- a/arnold/__init__.py +++ b/arnold/__init__.py @@ -14,11 +14,11 @@ class Terminator: IGNORED_FILES = ["__init__"] def __init__(self, args): - self.fake = getattr(args, 'fake', False) - self.count = getattr(args, 'count', 0) - self.folder = getattr(args, 'folder', None) + self.fake = args.get('fake', False) + self.count = args.get('count', 0) + self.folder = args.get('folder', None) - self.database = getattr(args, 'database', None) + self.database = args.get('database', None) if self.database is None: self.prepare_config() @@ -194,9 +194,10 @@ def status(args): def init(args): - os.makedirs('{0}/migrations'.format(args.folder)) - open('{0}/__init__.py'.format(args.folder), 'a').close() - open('{0}/migrations/__init__.py'.format(args.folder), 'a').close() + folder = args.get('folder') + os.makedirs('{0}/migrations'.format(folder)) + open('{0}/__init__.py'.format(folder), 'a').close() + open('{0}/migrations/__init__.py'.format(folder), 'a').close() return True @@ -238,7 +239,7 @@ def parse_args(args): 'count', type=int, help='How many migrations to go down.' ) - return parser.parse_args(args) + return vars(parser.parse_args(args)) def main(): sys.argv.pop(0) diff --git a/tests/__init__.py b/tests/__init__.py index f42f332..621e430 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -126,5 +126,15 @@ def test_init_creates_folders(self): self.assertTrue(os.path.isfile('./test_config/__init__.py')) self.assertTrue(os.path.isfile('./test_config/migrations/__init__.py')) + def test_database_arg_runs_up(self): + args = { + 'database': db, + 'count': 1, + 'folder': 'arnold_config', + } + termi = Terminator(args) + termi.perform_migrations('up') + self.assertTrue("basicmodel" in db.get_tables()) + if __name__ == '__main__': unittest.main() From de5a467d2323ee85178975a4d0963031822f4233 Mon Sep 17 00:00:00 2001 From: Cameron Stitt Date: Tue, 22 Nov 2016 20:47:21 +1000 Subject: [PATCH 3/4] Allow for database arg --- .gitignore | 2 ++ setup.py | 2 +- tests/__init__.py | 7 ++----- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 6c98098..f597aa5 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,8 @@ dist build eggs +.eggs +include parts bin var diff --git a/setup.py b/setup.py index 7db40a7..14a1b85 100644 --- a/setup.py +++ b/setup.py @@ -9,7 +9,7 @@ setup( name='arnold', - version='0.4.1', + version='0.5.0', description='Simple migrations for python ORMs', long_description='', keywords='python, peewee, migrations', diff --git a/tests/__init__.py b/tests/__init__.py index 621e430..aabe8fe 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -127,11 +127,8 @@ def test_init_creates_folders(self): self.assertTrue(os.path.isfile('./test_config/migrations/__init__.py')) def test_database_arg_runs_up(self): - args = { - 'database': db, - 'count': 1, - 'folder': 'arnold_config', - } + args = parse_args(['up', '1']) + args['database'] = db termi = Terminator(args) termi.perform_migrations('up') self.assertTrue("basicmodel" in db.get_tables()) From f29f232a9040a9450ffdcfbea2aaa8d6950ab490 Mon Sep 17 00:00:00 2001 From: Cameron Stitt Date: Tue, 22 Nov 2016 20:49:47 +1000 Subject: [PATCH 4/4] Test 3.4 and 3.5 too. --- .travis.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index fc80ff7..62e1d8f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,8 @@ python: - "2.7" - "3.2" - "3.3" + - "3.4" + - "3.5" # does not have headers provided, please ask https://launchpad.net/~pypy/+archive/ppa # maintainers to fix their pypy-dev package. - "pypy" @@ -12,4 +14,4 @@ install: # command to run tests script: - cd tests - - nosetests \ No newline at end of file + - nosetests