def setUp(self): super(TestCat, self).setUp() def restore_stdout(): sys.stdout = self._stdout_orig # Redirect sys.stdout as this is what cat uses self.outf = StringIOWrapper() self._stdout_orig = sys.stdout sys.stdout = self.outf self.addCleanup(restore_stdout)
def setUp(self): self._stderr = sys.stderr self._getpreferredencoding = locale.getpreferredencoding self.addCleanup(self._reset) sys.stderr = StringIOWrapper() # save $LANG self._LANG = os.environ.get('LANG')
class TestCat(TestCaseWithConnectionHookedTransport): def setUp(self): super(TestCat, self).setUp() # Redirect sys.stdout as this is what cat uses self.outf = StringIOWrapper() self.overrideAttr(sys, 'stdout', self.outf) def test_cat(self): # FIXME: sftp raises ReadError instead of NoSuchFile when probing for # branch/foo/.bzr/branch-format when used with the paramiko test # server. from bzrlib.tests import TestSkipped raise TestSkipped('SFTPTransport raises incorrect exception' ' when reading from paramiko server') wt1 = self.make_branch_and_tree('branch') self.build_tree_contents([('branch/foo', 'foo')]) wt1.add('foo') wt1.commit('add foo') self.start_logging_connections() cmd = cmd_cat() cmd.run(self.get_url('branch/foo')) self.assertEquals(1, len(self.connections)) self.assertEquals('foo', self.outf.getvalue())
class TestCat(TestCaseWithConnectionHookedTransport): def setUp(self): super(TestCat, self).setUp() # Redirect sys.stdout as this is what cat uses self.outf = StringIOWrapper() self.overrideAttr(sys, 'stdout', self.outf) def test_cat(self): # FIXME: sftp raises ReadError instead of NoSuchFile when probing for # branch/foo/.bzr/branch-format when used with the paramiko test # server. from bzrlib.tests import TestSkipped raise TestSkipped('SFTPTransport raises incorrect exception' ' when reading from paramiko server') wt1 = self.make_branch_and_tree('branch') self.build_tree_contents([('branch/foo', 'foo')]) wt1.add('foo') wt1.commit('add foo') self.start_logging_connections() cmd = cmd_cat() cmd.run(self.get_url('branch/foo')) self.assertEqual(1, len(self.connections)) self.assertEqual('foo', self.outf.getvalue())
def test_text_factory_utf8_password(self): """Test an utf8 password. We can't predict what encoding users will have for stdin, so we force it to utf8 to test that we transport the password correctly. """ ui = TestUIFactory(stdin=u'baz\u1234'.encode('utf8'), stdout=StringIOWrapper()) ui.stdin.encoding = 'utf8' ui.stdout.encoding = ui.stdin.encoding pb = ui.nested_progress_bar() try: password = self.apply_redirected(ui.stdin, ui.stdout, ui.stdout, ui.get_password, u'Hello \u1234 %(user)s', user=u'some\u1234') # We use StringIO objects, we need to decode them self.assertEqual(u'baz\u1234', password.decode('utf8')) self.assertEqual(u'Hello \u1234 some\u1234: ', ui.stdout.getvalue().decode('utf8')) # stdin should be empty self.assertEqual('', ui.stdin.readline()) finally: pb.finished()
def make_wrapped_streams(self, stdout_encoding, stderr_encoding, stdin_encoding, user_encoding='user_encoding', enable_fake_encodings=True): sys.stdout = StringIOWrapper() sys.stdout.encoding = stdout_encoding sys.stderr = StringIOWrapper() sys.stderr.encoding = stderr_encoding sys.stdin = StringIOWrapper() sys.stdin.encoding = stdin_encoding bzrlib.user_encoding = user_encoding if enable_fake_encodings: fake_codec.add(stdout_encoding) fake_codec.add(stderr_encoding) fake_codec.add(stdin_encoding)
def test_merge(self): wt1 = self.make_branch_and_tree('branch1') wt1.commit('empty commit') wt2 = self.make_branch_and_tree('branch2') wt2.pull(wt1.branch) wt2.commit('empty commit too') self.start_logging_connections() cmd = cmd_merge() # We don't care about the ouput but 'outf' should be defined cmd.outf = StringIOWrapper() cmd.run(self.get_url('branch1'), directory='branch2') self.assertEquals(1, len(self.connections))
def test_text_factory_ascii_password(self): ui = TestUIFactory(stdin='secret\n', stdout=StringIOWrapper()) pb = ui.nested_progress_bar() try: self.assertEqual( 'secret', self.apply_redirected(ui.stdin, ui.stdout, ui.stdout, ui.get_password)) # ': ' is appended to prompt self.assertEqual(': ', ui.stdout.getvalue()) # stdin should be empty self.assertEqual('', ui.stdin.readline()) finally: pb.finished()
def setUp(self): super(TestUserEncoding, self).setUp() self.overrideAttr(osutils, '_cached_user_encoding', None) self.overrideAttr(locale, 'getpreferredencoding', self.get_encoding) self.overrideAttr(locale, 'CODESET', None) self.overrideAttr(sys, 'stderr', StringIOWrapper())
def setUp(self): super(TestCat, self).setUp() # Redirect sys.stdout as this is what cat uses self.outf = StringIOWrapper() self.overrideAttr(sys, 'stdout', self.outf)