def test_openstack_out_get_field_ok_uuids_input(self): with utils.stringio(neutron_agent_list) as fin: with utils.redirect('stdin', iofile=fin): f = self.get_field(['-p', 'Metadata', '-c', '0', '--']) print(f) u = uuid.UUID(f[0][0]) self.assertEqual(uuid.UUID, type(u)) with utils.stringio(neutron_agent_list) as fin: with utils.redirect('stdin', iofile=fin): f = self.get_field(['-P', 'c7-netw', '--']) print(f) u = uuid.UUID(f[0][0]) self.assertEqual(uuid.UUID, type(u))
def test_glancing_add_checksum(self): with utils.stringio() as output: with utils.redirect('stdout', output): self.assertFalse(glancing.add_checksum(self._CIRROS_MD5, {'checksums': {'md5': '0' * 32}})) self.assertEqual(output.getvalue(), '%s: conflicting digests: %s:%s\n' % (sys.argv[0], self._CIRROS_MD5, '0' * 32))
def test_utils_redirect_print(self): with utils.stringio() as output: with utils.redirect('stdout', output): print('TOTOTITI') self.assertEqual('TOTOTITI\n', output.getvalue()) self.assertEqual('TOTOTITI\n', output.getvalue()) with self.assertRaises(ValueError): output.getvalue()
def test_glancing_add_checksum(self): with utils.stringio() as output: with utils.redirect('stdout', output): self.assertFalse( glancing.add_checksum(self._CIRROS_MD5, {'checksums': { 'md5': '0' * 32 }})) self.assertEqual( output.getvalue(), '%s: conflicting digests: %s:%s\n' % (sys.argv[0], self._CIRROS_MD5, '0' * 32))
def test_multihash_gethash_serial_nonexistent_hash(self): mh = multihash.multihash_serial_exec() with utils.stringio() as output: with utils.redirect('stdout', output): nonexistent_hash = 'nonexistent_hash_algo' self.assertFalse(mh.get_hash(os.devnull, nonexistent_hash)) out = ("%s: '%s%s': Cannot execute, please check it is properly" " installed, and available through your PATH environment " "variable.\n%s: [Errno 2] No such file or directory\n" % (sys.argv[0], nonexistent_hash, 'sum', sys.argv[0])) out = out.split("\n")[0] self.assertEqual(output.getvalue().split("\n")[0], out)
def vprint_lines_verbose(self, verbosity, test_name): v = utils.get_verbose() utils.set_verbose(verbosity) with utils.stringio() as output: expected = '' if verbosity: expected = test_name + ': TOTO\n' + test_name + ': TITI\n' with utils.redirect('stdout', output): utils.vprint_lines('TOTO\nTITI', test_name) self.assertEqual(expected, output.getvalue()) self.assertEqual(expected, output.getvalue()) with self.assertRaises(ValueError): output.getvalue() utils.set_verbose(v)
def test_utils_stringio_read(self): with utils.stringio() as out: self.assertEqual('', out.getvalue()) self.assertEqual('', out.read()) out.write('TOTO') self.assertEqual('TOTO', out.getvalue()) self.assertEqual('', out.read()) out.seek(0) self.assertEqual('TOTO', out.getvalue()) self.assertEqual('TOTO', out.read()) out.seek(0, os.SEEK_END) out.write('TITI') self.assertEqual('TOTOTITI', out.getvalue()) self.assertEqual('', out.read()) out.seek(0) self.assertEqual('TOTOTITI', out.read()) out.seek(0) out.write('TITI') self.assertEqual('TITITITI', out.getvalue()) self.assertEqual('TITI', out.read()) out.seek(0) self.assertEqual('TITITITI', out.read()) self.assertTrue(out.closed)
def test_utils_redirect_run_out(self): with utils.stringio() as output: with utils.redirect('stdout', output): utils.run(['echo', 'TOTO'], out=True) self.assertEqual('', output.getvalue())
def test_openstack_out_main(self): with utils.stringio() as output: with utils.redirect('stdout', output): openstack_out.main( ['-p', 'm1.tiny', '-c', '2', '--', 'nova', 'flavor-list']) self.assertEqual(output.getvalue(), '512\n')
def test_utils_redirect_write(self): with utils.stringio() as output: with utils.redirect('stdout', output): sys.stdout.write('TOTO') self.assertEqual('TOTO', output.getvalue())
def test_utils_stringio_write(self): with utils.stringio() as out: out.write('TOTO') self.assertEqual('TOTO', out.getvalue()) self.assertTrue(out.closed)
def test_openstack_out_main(self): with utils.stringio() as output: with utils.redirect('stdout', output): openstack_out.main(['-p', 'm1.tiny', '-c', '2', '--', 'nova', 'flavor-list']) self.assertEqual(output.getvalue(), '512\n')