diff options
Diffstat (limited to 'tests/test_command.py')
-rw-r--r-- | tests/test_command.py | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/tests/test_command.py b/tests/test_command.py index 0061023..ffb659b 100644 --- a/tests/test_command.py +++ b/tests/test_command.py @@ -1,4 +1,5 @@ from alembic import command +from mock import patch from io import TextIOWrapper, BytesIO from alembic.script import ScriptDirectory from alembic.testing.fixtures import TestBase, capture_context_buffer @@ -371,3 +372,50 @@ down_revision = '%s' self.bind.scalar("select version_num from alembic_version"), self.a ) + + +class EditTest(TestBase): + + @classmethod + def setup_class(cls): + cls.env = staging_env() + cls.cfg = _sqlite_testing_config() + cls.a, cls.b, cls.c = three_rev_fixture(cls.cfg) + + @classmethod + def teardown_class(cls): + clear_staging_env() + + def test_edit_with_user_editor(self): + expected_call_arg = '%s/scripts/versions/%s_revision_c.py' % ( + EditTest.cfg.config_args['here'], + EditTest.c + ) + + with patch('alembic.util.os_helpers.check_call') as check_call, \ + patch('alembic.util.os_helpers.exists') as exists: + exists.side_effect = lambda fname: fname == '/usr/bin/vim' + command.edit(self.cfg) + check_call.assert_called_with(['/usr/bin/vim', expected_call_arg]) + + def test_edit_with_default_editor(self): + expected_call_arg = '%s/scripts/versions/%s_revision_c.py' % ( + EditTest.cfg.config_args['here'], + EditTest.c + ) + + with patch('alembic.util.os_helpers.check_call') as check_call, \ + patch('alembic.util.os_helpers.exists') as exists: + exists.side_effect = lambda fname: fname == '/usr/bin/vim' + command.edit(self.cfg) + check_call.assert_called_with(['/usr/bin/vim', expected_call_arg]) + + def test_edit_with_missing_editor(self): + with patch('alembic.util.os_helpers.check_call'), \ + patch('alembic.util.os_helpers.exists') as exists: + exists.return_value = False + assert_raises_message( + util.CommandError, + 'EDITOR', + command.edit, + self.cfg) |