From d22401f101c0b726af464cc26d8a7c8485d7d532 Mon Sep 17 00:00:00 2001 From: David Wobrock Date: Mon, 21 Jan 2019 22:21:33 +0100 Subject: [PATCH] Add tests for version option From Python 3.4 on, version is printed on stdout instead of stderr. --- tests/functional/test_cmd_line_call.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/tests/functional/test_cmd_line_call.py b/tests/functional/test_cmd_line_call.py index a2861fae..47d7944a 100644 --- a/tests/functional/test_cmd_line_call.py +++ b/tests/functional/test_cmd_line_call.py @@ -16,7 +16,7 @@ import shutil import unittest from subprocess import Popen, PIPE -from django_migration_linter import utils, DEFAULT_CACHE_PATH +from django_migration_linter import utils, DEFAULT_CACHE_PATH, constants from tests import fixtures import sys @@ -274,3 +274,25 @@ def test_call_project_non_git_root_ko(self): self.assertTrue(lines[0].endswith('ERR')) self.assertTrue(lines[2].endswith('OK')) self.assertTrue(lines[3].startswith('*** Summary')) + + +class VersionOptionLinterFromCommandLineTest(CallLinterFromCommandLineTest): + def test_call_with_version_option(self): + cmd = "{} --version".format(self.linter_exec) + process = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE) + process.wait() + self.assertEqual(process.returncode, 0) + process_read_stream = process.stderr if sys.version_info.major == 2 else process.stdout + lines = list(map(utils.clean_bytes_to_str, process_read_stream.readlines())) + self.assertEqual(len(lines), 1) + self.assertEqual(lines[0], "django-migration-linter {}".format(constants.__version__)) + + def test_call_with_short_version_option(self): + cmd = "{} -V".format(self.linter_exec) + process = Popen(cmd, shell=True, stdout=PIPE, stderr=PIPE) + process.wait() + self.assertEqual(process.returncode, 0) + process_read_stream = process.stderr if sys.version_info.major == 2 else process.stdout + lines = list(map(utils.clean_bytes_to_str, process_read_stream.readlines())) + self.assertEqual(len(lines), 1) + self.assertEqual(lines[0], "django-migration-linter {}".format(constants.__version__))