aboutsummaryrefslogtreecommitdiff
path: root/run_unittests.py
diff options
context:
space:
mode:
authorAleksey Filippov <alekseyf@google.com>2018-03-26 00:13:02 +0000
committerJussi Pakkanen <jpakkane@gmail.com>2018-03-26 23:47:51 +0300
commit977acc94b84077e84da7ddde4099e96f03530038 (patch)
tree1666671387e9a08ca3af407a468ffd04ff4cea6e /run_unittests.py
parent8efd9400922f6f8eb876f9ef8d0042679d836c90 (diff)
downloadmeson-977acc94b84077e84da7ddde4099e96f03530038.zip
meson-977acc94b84077e84da7ddde4099e96f03530038.tar.gz
meson-977acc94b84077e84da7ddde4099e96f03530038.tar.bz2
Do not leave open file handlers, use context manager to clean them up
Diffstat (limited to 'run_unittests.py')
-rwxr-xr-xrun_unittests.py15
1 files changed, 9 insertions, 6 deletions
diff --git a/run_unittests.py b/run_unittests.py
index 0c84475..6ab549c 100755
--- a/run_unittests.py
+++ b/run_unittests.py
@@ -439,10 +439,11 @@ class InternalTests(unittest.TestCase):
for f in snippet_dir.glob('*'):
self.assertTrue(f.is_file())
if f.suffix == '.md':
- for line in f.open():
- m = re.match(hashcounter, line)
- if m:
- self.assertEqual(len(m.group(0)), 2, 'All headings in snippets must have two hash symbols: ' + f.name)
+ with f.open() as snippet:
+ for line in snippet:
+ m = re.match(hashcounter, line)
+ if m:
+ self.assertEqual(len(m.group(0)), 2, 'All headings in snippets must have two hash symbols: ' + f.name)
else:
if f.name != 'add_release_note_snippets_here':
self.assertTrue(False, 'A file without .md suffix in snippets dir: ' + f.name)
@@ -1811,7 +1812,8 @@ int main(int argc, char **argv) {
self._run(ninja,
workdir=os.path.join(tmpdir, 'builddir'))
with tempfile.TemporaryDirectory() as tmpdir:
- open(os.path.join(tmpdir, 'foo.' + lang), 'w').write('int main() {}')
+ with open(os.path.join(tmpdir, 'foo.' + lang), 'w') as f:
+ f.write('int main() {}')
self._run(meson_command + ['init', '-b'], workdir=tmpdir)
# The test uses mocking and thus requires that
@@ -2296,7 +2298,8 @@ class LinuxlikeTests(BasePlatformTests):
def test_pkg_unfound(self):
testdir = os.path.join(self.unit_test_dir, '22 unfound pkgconfig')
self.init(testdir)
- pcfile = open(os.path.join(self.privatedir, 'somename.pc')).read()
+ with open(os.path.join(self.privatedir, 'somename.pc')) as f:
+ pcfile = f.read()
self.assertFalse('blub_blob_blib' in pcfile)
def test_vala_c_warnings(self):