def UnexpectedExit_str_encodes_stdout_and_err(self, mock_exit): p = Program() oops = UnexpectedExit( Result( command='meh', exited=54, stdout=six.u('this is not ascii: \u1234'), stderr=six.u('this is also not ascii: \u4321'), encoding='utf-8', hide=('stdout', 'stderr'), )) p.execute = Mock(side_effect=oops) p.run("myapp foo") # NOTE: using explicit binary ASCII here, & accessing raw # getvalue() of the faked sys.stderr (spec.trap auto-decodes it # normally) to have a not-quite-tautological test. otherwise we'd # just be comparing unicode to unicode. shrug? expected = b"""Encountered a bad command exit code! Command: 'meh' Exit code: 54 Stdout: this is not ascii: \xe1\x88\xb4 Stderr: this is also not ascii: \xe4\x8c\xa1 """ got = six.BytesIO.getvalue(sys.stderr) assert got == expected
def unicode_replaced_with_env_value(self): # Python 3 doesn't allow you to put 'bytes' objects into # os.environ, so the test makes no sense there. if six.PY3: return os.environ['INVOKE_FOO'] = 'myunicode' c = Config(defaults={'foo': six.u('myoldvalue')}) c.load_shell_env() eq_(c.foo, 'myunicode') ok_(isinstance(c.foo, str))
def strings_replaced_with_env_value(self): os.environ['INVOKE_FOO'] = six.u('myvalue') c = Config(defaults={'foo': 'myoldvalue'}) c.load_shell_env() eq_(c.foo, six.u('myvalue')) ok_(isinstance(c.foo, six.text_type))