From 14596a8849c1ee7b70378acf90ddb9e93d0ca25e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jelmer=20Vernoo=C4=B3?= Date: Wed, 18 Sep 2024 12:33:30 +0000 Subject: [PATCH] Fix parse_args test on Windows --- tests/test_main.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/tests/test_main.py b/tests/test_main.py index af42721..1deeb31 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -2,6 +2,7 @@ # Copyright (C) 2018 Jelmer Vernooij # +import os import tempfile import unittest from prometheus_xmpp.__main__ import parse_args @@ -18,17 +19,19 @@ def test_parse_args_env(self): self.assertEqual(config['amtool_allowed'], ['jelmer@jelmer.uk']) def test_parse_args_config(self): - with tempfile.NamedTemporaryFile() as f: - f.write(b"""\ + f = tempfile.NamedTemporaryFile(delete=False) + self.addCleanup(os.remove, f.name) + f.write(b"""\ jid: foo@bar password: baz to_jid: jelmer@jelmer.uk amtool_allowed: foo@example.com """) - f.flush() - (jid, password_cb, recipients, config) = parse_args(['--config', f.name], env={}) + f.flush() + f.close() + (jid, password_cb, recipients, config) = parse_args(['--config', f.name], env={}) - self.assertTrue(jid.startswith('foo@bar/')) - self.assertEqual(password_cb(), 'baz') - self.assertEqual(recipients, ['jelmer@jelmer.uk']) - self.assertEqual(config['amtool_allowed'], ['foo@example.com']) + self.assertTrue(jid.startswith('foo@bar/')) + self.assertEqual(password_cb(), 'baz') + self.assertEqual(recipients, ['jelmer@jelmer.uk']) + self.assertEqual(config['amtool_allowed'], ['foo@example.com'])