def testToJson(self): self.mock(git_footers.sys, 'stdin', StringIO.StringIO( 'line\r\nany spaces\r\n\r\n\r\nFoo: 1\nBar: 2\nFoo: 3')) with tempfile.NamedTemporaryFile() as tmp: self.assertEqual(git_footers.main(['--json', tmp.name]), 0) js = json.load(open(tmp.name)) self.assertEqual(js, {'Foo': ['3', '1'], 'Bar': ['2']})
def testReadStdin(self): self.mock(git_footers.sys, 'stdin', StringIO.StringIO( 'line\r\notherline\r\n\r\n\r\nFoo: baz')) stdout = StringIO.StringIO() self.mock(git_footers.sys, 'stdout', stdout) self.assertEqual(git_footers.main([]), 0) self.assertEqual(stdout.getvalue(), "Foo: baz\n")
def testReadStdin(self): self.mock(git_footers.sys, 'stdin', StringIO.StringIO( 'line\r\notherline\r\n\r\n\r\nFoo: baz\r\nStill: footer')) stdout = StringIO.StringIO() self.mock(git_footers.sys, 'stdout', stdout) self.assertEqual(git_footers.main([]), 0) self.assertEqual(stdout.getvalue(), 'Still: footer\nFoo: baz\n')
def testToJson(self): self.mock( git_footers.sys, 'stdin', StringIO.StringIO( 'line\r\nany spaces\r\n\r\n\r\nFoo: 1\nBar: 2\nFoo: 3')) with tempfile.NamedTemporaryFile() as tmp: self.assertEqual(git_footers.main(['--json', tmp.name]), 0) js = json.load(open(tmp.name)) self.assertEqual(js, {'Foo': ['3', '1'], 'Bar': ['2']})
def testToJson(self): with tempfile.NamedTemporaryFile(delete=False) as tmp: try: # NamedTemporaryFiles must be closed on Windows before being opened # again. tmp.close() self.assertEqual(git_footers.main(['--json', tmp.name]), 0) js = json.load(open(tmp.name)) finally: os.remove(tmp.name) self.assertEqual(js, {'Foo': ['3', '1'], 'Bar': ['2']})
def testToJson(self): with gclient_utils.temporary_file() as tmp: self.assertEqual(git_footers.main(['--json', tmp]), 0) with open(tmp) as f: js = json.load(f) self.assertEqual(js, {'Foo': ['3', '1'], 'Bar': ['2']})
def testReadStdin(self): self.assertEqual(git_footers.main([]), 0) self.assertEqual(sys.stdout.getvalue(), 'Still: footer\nFoo: baz\n')