Skip to content

Commit

Permalink
tests: Use sys.executable (#290)
Browse files Browse the repository at this point in the history
Also re-order imports.

Closes #289
  • Loading branch information
jayvdb authored and miguelgrinberg committed Sep 14, 2019
1 parent d4aacb3 commit e5135e5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
25 changes: 13 additions & 12 deletions tests/test_migrate.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import os
import shlex
import shutil
import unittest
import subprocess
import shlex
import sys
import unittest


def run_cmd(cmd):
Expand Down Expand Up @@ -53,37 +54,37 @@ def test_alembic_version(self):
self.assertTrue(isinstance(v, int))

def test_migrate_upgrade(self):
(o, e, s) = run_cmd('python app.py db init')
(o, e, s) = run_cmd(sys.executable + ' app.py db init')
self.assertTrue(s == 0)
(o, e, s) = run_cmd('python app.py db migrate')
(o, e, s) = run_cmd(sys.executable + ' app.py db migrate')
self.assertTrue(s == 0)
(o, e, s) = run_cmd('python app.py db upgrade')
(o, e, s) = run_cmd(sys.executable + ' app.py db upgrade')
self.assertTrue(s == 0)

from .app import db, User
db.session.add(User(name='test'))
db.session.commit()

def test_custom_directory(self):
(o, e, s) = run_cmd('python app_custom_directory.py db init')
(o, e, s) = run_cmd(sys.executable + ' app_custom_directory.py db init')
self.assertTrue(s == 0)
(o, e, s) = run_cmd('python app_custom_directory.py db migrate')
(o, e, s) = run_cmd(sys.executable + ' app_custom_directory.py db migrate')
self.assertTrue(s == 0)
(o, e, s) = run_cmd('python app_custom_directory.py db upgrade')
(o, e, s) = run_cmd(sys.executable + ' app_custom_directory.py db upgrade')
self.assertTrue(s == 0)

from .app_custom_directory import db, User
db.session.add(User(name='test'))
db.session.commit()

def test_compare_type(self):
(o, e, s) = run_cmd('python app_compare_type1.py db init')
(o, e, s) = run_cmd(sys.executable + ' app_compare_type1.py db init')
self.assertTrue(s == 0)
(o, e, s) = run_cmd('python app_compare_type1.py db migrate')
(o, e, s) = run_cmd(sys.executable + ' app_compare_type1.py db migrate')
self.assertTrue(s == 0)
(o, e, s) = run_cmd('python app_compare_type1.py db upgrade')
(o, e, s) = run_cmd(sys.executable + ' app_compare_type1.py db upgrade')
self.assertTrue(s == 0)
(o, e, s) = run_cmd('python app_compare_type2.py db migrate')
(o, e, s) = run_cmd(sys.executable + ' app_compare_type2.py db migrate')
self.assertTrue(s == 0)
self.assertTrue(b'Detected type change from VARCHAR(length=128) '
b'to String(length=10)' in e)
15 changes: 8 additions & 7 deletions tests/test_multidb_migrate.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import os
import shutil
import unittest
import subprocess
import shlex
import shutil
import sqlite3
import subprocess
import sys
import unittest


def run_cmd(cmd):
Expand Down Expand Up @@ -39,11 +40,11 @@ def tearDown(self):
pass

def test_multidb_migrate_upgrade(self):
(o, e, s) = run_cmd('python app_multidb.py db init --multidb')
(o, e, s) = run_cmd(sys.executable + ' app_multidb.py db init --multidb')
self.assertTrue(s == 0)
(o, e, s) = run_cmd('python app_multidb.py db migrate')
(o, e, s) = run_cmd(sys.executable + ' app_multidb.py db migrate')
self.assertTrue(s == 0)
(o, e, s) = run_cmd('python app_multidb.py db upgrade')
(o, e, s) = run_cmd(sys.executable + ' app_multidb.py db upgrade')
self.assertTrue(s == 0)

# ensure the tables are in the correct databases
Expand All @@ -70,7 +71,7 @@ def test_multidb_migrate_upgrade(self):
db.session.commit()

# ensure the downgrade works
(o, e, s) = run_cmd('python app_multidb.py db downgrade')
(o, e, s) = run_cmd(sys.executable + ' app_multidb.py db downgrade')
self.assertTrue(s == 0)

conn1 = sqlite3.connect('app1.db')
Expand Down

0 comments on commit e5135e5

Please sign in to comment.