comparison tests/test_util.py @ 334:3c3c3264c362

test_util: Make the patching of ui.ui.write_err() slightly more reusable.
author Dan Villiom Podlaski Christiansen <danchr@gmail.com>
date Tue, 12 May 2009 20:14:15 +0200
parents a59ab58969d9
children 46e69be8e2c8
comparison
equal deleted inserted replaced
333:a59ab58969d9 334:3c3c3264c362
79 self.tmpdir = tempfile.mkdtemp( 79 self.tmpdir = tempfile.mkdtemp(
80 'svnwrap_test', dir=os.environ.get('HGSUBVERSION_TEST_TEMP', None)) 80 'svnwrap_test', dir=os.environ.get('HGSUBVERSION_TEST_TEMP', None))
81 self.hgrc = os.path.join(self.tmpdir, '.hgrc') 81 self.hgrc = os.path.join(self.tmpdir, '.hgrc')
82 os.environ['HGRCPATH'] = self.hgrc 82 os.environ['HGRCPATH'] = self.hgrc
83 rc = open(self.hgrc, 'w') 83 rc = open(self.hgrc, 'w')
84 rc.write('[extensions]\nhgsubversion=') 84 for l in '[extensions]', 'hgsubversion=':
85 print >> rc, l
85 86
86 self.repo_path = '%s/testrepo' % self.tmpdir 87 self.repo_path = '%s/testrepo' % self.tmpdir
87 self.wc_path = '%s/testrepo_wc' % self.tmpdir 88 self.wc_path = '%s/testrepo_wc' % self.tmpdir
88 89
89 # Previously, we had a MockUI class that wrapped ui, and giving access 90 # Previously, we had a MockUI class that wrapped ui, and giving access
90 # to the stream. The ui.pushbuffer() and ui.popbuffer() can be used 91 # to the stream. The ui.pushbuffer() and ui.popbuffer() can be used
91 # instead. Using the regular UI class, with all stderr redirected to 92 # instead. Using the regular UI class, with all stderr redirected to
92 # stdout ensures that the test setup is much more similar to usage 93 # stdout ensures that the test setup is much more similar to usage
93 # setups. 94 # setups.
94 self._ui_write_err = ui.ui.write_err 95 self.patch = (ui.ui.write_err, ui.ui.write)
95 ui.ui.write_err = ui.ui.write 96 setattr(ui.ui, self.patch[0].func_name, self.patch[1])
96 97
97 def tearDown(self): 98 def tearDown(self):
98 rmtree(self.tmpdir) 99 rmtree(self.tmpdir)
99 os.chdir(self.oldwd) 100 os.chdir(self.oldwd)
100 ui.ui.write_err = self._ui_write_err 101 setattr(ui.ui, self.patch[0].func_name, self.patch[0])
101 102
102 def _load_fixture_and_fetch(self, fixture_name, subdir='', stupid=False): 103 def _load_fixture_and_fetch(self, fixture_name, subdir='', stupid=False):
103 return load_fixture_and_fetch(fixture_name, self.repo_path, 104 return load_fixture_and_fetch(fixture_name, self.repo_path,
104 self.wc_path, subdir=subdir, 105 self.wc_path, subdir=subdir,
105 stupid=stupid) 106 stupid=stupid)