def test_no_progress_when_stderr_not_a_tty(self): # Create a collection with a big file (>64MB) to force the progress # to be printed c = collection.Collection() with c.open('bigfile.txt', 'wb') as f: for _ in range(65): f.write("x" * 1024 * 1024) c.save_new() tmpdir = self.make_tmpdir() # Simulate a TTY stderr stderr = mock.MagicMock() stdout = tutil.BytesIO() # Confirm that progress is written to stderr when is a tty stderr.isatty.return_value = True r = arv_get.main(['{}/bigfile.txt'.format(c.manifest_locator()), '{}/bigfile.txt'.format(tmpdir)], stdout, stderr) self.assertEqual(0, r) self.assertEqual(b'', stdout.getvalue()) self.assertTrue(stderr.write.called) # Clean up and reset stderr mock os.remove('{}/bigfile.txt'.format(tmpdir)) stderr = mock.MagicMock() stdout = tutil.BytesIO() # Confirm that progress is not written to stderr when isn't a tty stderr.isatty.return_value = False r = arv_get.main(['{}/bigfile.txt'.format(c.manifest_locator()), '{}/bigfile.txt'.format(tmpdir)], stdout, stderr) self.assertEqual(0, r) self.assertEqual(b'', stdout.getvalue()) self.assertFalse(stderr.write.called)
def write_test_collection(self, contents = { 'foo.txt' : 'foo', 'bar.txt' : 'bar', 'subdir/baz.txt' : 'baz', }): c = collection.Collection() for path, data in contents.items(): with c.open(path, 'w') as f: f.write(data) c.save_new() return (c.manifest_locator(), c.portable_data_hash(), c.manifest_text())