Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fix problem when using with gunicorn (django command) #10

Merged
merged 2 commits into from

2 participants

@snbuback

Fix a bug when using simple-db-migrate as app in django with gunicorn.
Gunicorn change sys.stdout to a LazyWriter and this object hasn't encoding attribute.

@wandenberg wandenberg merged commit 86a044c into guilhermechapiewski:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 7 additions and 2 deletions.
  1. +2 −2 simple_db_migrate/__init__.py
  2. +5 −0 tests/run_test.py
View
4 simple_db_migrate/__init__.py
@@ -6,10 +6,10 @@
from config import FileConfig, Config
from main import Main
-SIMPLE_DB_MIGRATE_VERSION = '1.5.2'
+SIMPLE_DB_MIGRATE_VERSION = '1.5.3'
# fixing print in non-utf8 terminals
-if sys.stdout.encoding != 'UTF-8':
+if hasattr(sys.stdout, 'encoding') and sys.stdout.encoding != 'UTF-8':
sys.stdout = codecs.getwriter('utf-8')(sys.stdout)
def run_from_argv(args=None):
View
5 tests/run_test.py
@@ -41,6 +41,11 @@ def test_it_should_ensure_stdout_is_using_an_utf8_encoding(self, stdout_mock, co
codecs_mock.assert_called_with('utf-8')
self.assertEqual(new_stdout, sys.stdout)
+ @patch('sys.stdout', new_callable=object)
+ def test_it_should_not_break_when_sys_stdout_has_not_encoding_property(self, stdout_mock):
+ reload(simple_db_migrate)
+ self.assertIs(stdout_mock, sys.stdout)
+
def test_it_should_define_a_version_string(self):
self.assertTrue(isinstance(simple_db_migrate.SIMPLE_DB_MIGRATE_VERSION, str))
Something went wrong with that request. Please try again.