diff options
author | Javier Santacruz <javier.santacruz.lc@gmail.com> | 2013-10-17 17:24:28 +0200 |
---|---|---|
committer | Javier Santacruz <javier.santacruz.lc@gmail.com> | 2013-10-17 17:24:28 +0200 |
commit | 227f1404a4012c52f75b270f237c6c6bc0579cc3 (patch) | |
tree | 7a936083c8b84b97c0690e049d6da97076761f18 /tests/test_offline_environment.py | |
parent | c84e3f1fd76a9fa7d8ee6221a21b7ed9188ba2f3 (diff) | |
download | alembic-227f1404a4012c52f75b270f237c6c6bc0579cc3.tar.gz |
Fixes stdout --sql output in python2
When output_encoding is set, wraps the output buffer into a io.TextIOWrapper class
This means that the output_buffer has to be a io.IOBase instance
in order to work along with the TextIOWrapper
Handles wrapping when the buffer is Python2 stdtout, which has 'file' type
Adds test for this situation
Diffstat (limited to 'tests/test_offline_environment.py')
-rw-r--r-- | tests/test_offline_environment.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/tests/test_offline_environment.py b/tests/test_offline_environment.py index 4a727d3..da2589c 100644 --- a/tests/test_offline_environment.py +++ b/tests/test_offline_environment.py @@ -1,3 +1,4 @@ +import io from unittest import TestCase from alembic import command, util @@ -11,6 +12,7 @@ class OfflineEnvironmentTest(TestCase): def setUp(self): env = staging_env() self.cfg = _no_sql_testing_config() + self.cfg.output_buffer = io.StringIO() global a, b, c a, b, c = three_rev_fixture(self.cfg) @@ -41,6 +43,8 @@ assert context.get_starting_revision_argument() == 'x' command.upgrade(self.cfg, a, sql=True) command.downgrade(self.cfg, "%s:%s" % (b, a), sql=True) command.current(self.cfg) + # current seems to close the buffer (?) + self.cfg.output_buffer = io.StringIO() command.stamp(self.cfg, a) def test_starting_rev_pre_context(self): @@ -153,3 +157,12 @@ context.configure(dialect_name='sqlite') command.downgrade, self.cfg, b, sql=True ) + + def test_upgrade_with_output_encoding(self): + env_file_fixture(""" +url = config.get_main_option('sqlalchemy.url') +context.configure(url=url, output_encoding='utf-8') +assert not context.requires_connection() +""") + command.upgrade(self.cfg, a, sql=True) + command.downgrade(self.cfg, "%s:%s" % (b, a), sql=True) |