From 9ee8c27ac95359e0f1fb2d82e632b04388b75b77 Mon Sep 17 00:00:00 2001 From: Mathieu Couette <12388398+MathieuCouette@users.noreply.github.com> Date: Tue, 29 Sep 2020 12:11:09 -0400 Subject: [PATCH] tests: Replace deprecated aliases https://docs.python.org/3/library/unittest.html#deprecated-aliases --- tests/test_cli.py | 16 ++++++++-------- tests/test_config.py | 6 +++--- tests/test_module.py | 4 ++-- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/tests/test_cli.py b/tests/test_cli.py index 020b371..b243b93 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -246,19 +246,19 @@ class CommandLineTestCase(unittest.TestCase): cli.run(()) self.assertNotEqual(ctx.returncode, 0) self.assertEqual(ctx.stdout, '') - self.assertRegexpMatches(ctx.stderr, r'^usage') + self.assertRegex(ctx.stderr, r'^usage') with RunContext(self) as ctx: cli.run(('--unknown-arg', )) self.assertNotEqual(ctx.returncode, 0) self.assertEqual(ctx.stdout, '') - self.assertRegexpMatches(ctx.stderr, r'^usage') + self.assertRegex(ctx.stderr, r'^usage') with RunContext(self) as ctx: cli.run(('-c', './conf.yaml', '-d', 'relaxed', 'file')) self.assertNotEqual(ctx.returncode, 0) self.assertEqual(ctx.stdout, '') - self.assertRegexpMatches( + self.assertRegex( ctx.stderr.splitlines()[-1], r'^yamllint: error: argument -d\/--config-data: ' r'not allowed with argument -c\/--config-file$' @@ -269,21 +269,21 @@ class CommandLineTestCase(unittest.TestCase): cli.run(('-', 'file')) self.assertNotEqual(ctx.returncode, 0) self.assertEqual(ctx.stdout, '') - self.assertRegexpMatches(ctx.stderr, r'^usage') + self.assertRegex(ctx.stderr, r'^usage') def test_run_with_bad_config(self): with RunContext(self) as ctx: cli.run(('-d', 'rules: {a: b}', 'file')) self.assertEqual(ctx.returncode, -1) self.assertEqual(ctx.stdout, '') - self.assertRegexpMatches(ctx.stderr, r'^invalid config: no such rule') + self.assertRegex(ctx.stderr, r'^invalid config: no such rule') def test_run_with_empty_config(self): with RunContext(self) as ctx: cli.run(('-d', '', 'file')) self.assertEqual(ctx.returncode, -1) self.assertEqual(ctx.stdout, '') - self.assertRegexpMatches(ctx.stderr, r'^invalid config: not a dict') + self.assertRegex(ctx.stderr, r'^invalid config: not a dict') def test_run_with_config_file(self): with open(os.path.join(self.wd, 'config'), 'w') as f: @@ -386,7 +386,7 @@ class CommandLineTestCase(unittest.TestCase): with RunContext(self) as ctx: cli.run(('--version', )) self.assertEqual(ctx.returncode, 0) - self.assertRegexpMatches(ctx.stdout + ctx.stderr, r'yamllint \d+\.\d+') + self.assertRegex(ctx.stdout + ctx.stderr, r'yamllint \d+\.\d+') def test_run_non_existing_file(self): path = os.path.join(self.wd, 'i-do-not-exist.yaml') @@ -395,7 +395,7 @@ class CommandLineTestCase(unittest.TestCase): cli.run(('-f', 'parsable', path)) self.assertEqual(ctx.returncode, -1) self.assertEqual(ctx.stdout, '') - self.assertRegexpMatches(ctx.stderr, r'No such file or directory') + self.assertRegex(ctx.stderr, r'No such file or directory') def test_run_one_problem_file(self): path = os.path.join(self.wd, 'a.yaml') diff --git a/tests/test_config.py b/tests/test_config.py index b48546c..01ca5af 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -48,7 +48,7 @@ class SimpleConfigTestCase(unittest.TestCase): config.YamlLintConfig('not: valid: yaml') def test_unknown_rule(self): - with self.assertRaisesRegexp( + with self.assertRaisesRegex( config.YamlLintConfigError, 'invalid config: no such rule: "this-one-does-not-exist"'): config.YamlLintConfig('rules:\n' @@ -67,7 +67,7 @@ class SimpleConfigTestCase(unittest.TestCase): self.assertEqual(c.rules['colons']['max-spaces-after'], 1) def test_unknown_option(self): - with self.assertRaisesRegexp( + with self.assertRaisesRegex( config.YamlLintConfigError, 'invalid config: unknown option "abcdef" for rule "colons"'): config.YamlLintConfig('rules:\n' @@ -105,7 +105,7 @@ class SimpleConfigTestCase(unittest.TestCase): self.assertEqual(c.rules['indentation']['check-multi-line-strings'], False) - with self.assertRaisesRegexp( + with self.assertRaisesRegex( config.YamlLintConfigError, 'invalid config: option "indent-sequences" of "indentation" ' 'should be in '): diff --git a/tests/test_module.py b/tests/test_module.py index e1bf066..0407ad8 100644 --- a/tests/test_module.py +++ b/tests/test_module.py @@ -47,7 +47,7 @@ class ModuleTestCase(unittest.TestCase): subprocess.check_output([PYTHON, '-m', 'yamllint'], stderr=subprocess.STDOUT) self.assertEqual(ctx.exception.returncode, 2) - self.assertRegexpMatches(ctx.exception.output.decode(), + self.assertRegex(ctx.exception.output.decode(), r'^usage: yamllint') def test_run_module_on_bad_dir(self): @@ -55,7 +55,7 @@ class ModuleTestCase(unittest.TestCase): subprocess.check_output([PYTHON, '-m', 'yamllint', '/does/not/exist'], stderr=subprocess.STDOUT) - self.assertRegexpMatches(ctx.exception.output.decode(), + self.assertRegex(ctx.exception.output.decode(), r'No such file or directory') def test_run_module_on_file(self):