Merge branch 'bugfix/disable_extensions_idfpy_tests' into 'master'

Tools: Make idf.py tests independent on extra extensions

Closes PACMAN-359

See merge request espressif/esp-idf!18275
This commit is contained in:
Roland Dobai 2022-05-27 18:57:32 +08:00
commit e096374560

View File

@ -6,7 +6,7 @@
import os import os
import subprocess import subprocess
import sys import sys
import unittest from unittest import TestCase, main, mock
try: try:
from StringIO import StringIO from StringIO import StringIO
@ -25,7 +25,20 @@ extension_path = os.path.join(current_dir, 'test_idf_extensions', 'test_ext')
link_path = os.path.join(current_dir, '..', 'idf_py_actions', 'test_ext') link_path = os.path.join(current_dir, '..', 'idf_py_actions', 'test_ext')
class TestExtensions(unittest.TestCase): class TestWithoutExtensions(TestCase):
@classmethod
def setUpClass(cls):
# Disable the component manager and extra extensions for these tests
cls.env_patcher = mock.patch.dict(os.environ, {
'IDF_COMPONENT_MANAGER': '0',
'IDF_EXTRA_ACTIONS_PATH': '',
})
cls.env_patcher.start()
super().setUpClass()
class TestExtensions(TestWithoutExtensions):
def test_extension_loading(self): def test_extension_loading(self):
try: try:
os.symlink(extension_path, link_path) os.symlink(extension_path, link_path)
@ -67,7 +80,7 @@ class TestExtensions(unittest.TestCase):
os.remove(link_path) os.remove(link_path)
class TestDependencyManagement(unittest.TestCase): class TestDependencyManagement(TestWithoutExtensions):
def test_dependencies(self): def test_dependencies(self):
result = idf.init_cli()( result = idf.init_cli()(
args=['--dry-run', 'flash'], args=['--dry-run', 'flash'],
@ -118,7 +131,7 @@ class TestDependencyManagement(unittest.TestCase):
'WARNING: Command "clean" is found in the list of commands more than once.', capturedOutput.getvalue()) 'WARNING: Command "clean" is found in the list of commands more than once.', capturedOutput.getvalue())
class TestVerboseFlag(unittest.TestCase): class TestVerboseFlag(TestWithoutExtensions):
def test_verbose_messages(self): def test_verbose_messages(self):
output = subprocess.check_output( output = subprocess.check_output(
[ [
@ -144,7 +157,7 @@ class TestVerboseFlag(unittest.TestCase):
self.assertNotIn('Verbose mode on', output) self.assertNotIn('Verbose mode on', output)
class TestGlobalAndSubcommandParameters(unittest.TestCase): class TestGlobalAndSubcommandParameters(TestWithoutExtensions):
def test_set_twice_same_value(self): def test_set_twice_same_value(self):
"""Can set -D twice: globally and for subcommand if values are the same""" """Can set -D twice: globally and for subcommand if values are the same"""
@ -163,21 +176,24 @@ class TestGlobalAndSubcommandParameters(unittest.TestCase):
) )
class TestDeprecations(unittest.TestCase): class TestDeprecations(TestWithoutExtensions):
def test_exit_with_error_for_subcommand(self): def test_exit_with_error_for_subcommand(self):
try: try:
subprocess.check_output([sys.executable, idf_py_path, '-C%s' % current_dir, 'test-2'], env=os.environ, subprocess.check_output(
stderr=subprocess.STDOUT) [sys.executable, idf_py_path, '-C%s' % current_dir, 'test-2'], env=os.environ, stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:
self.assertIn('Error: Command "test-2" is deprecated and was removed.', e.output.decode('utf-8', 'ignore')) self.assertIn('Error: Command "test-2" is deprecated and was removed.', e.output.decode('utf-8', 'ignore'))
def test_exit_with_error_for_option(self): def test_exit_with_error_for_option(self):
try: try:
subprocess.check_output([sys.executable, idf_py_path, '-C%s' % current_dir, '--test-5=asdf'], subprocess.check_output(
env=os.environ, stderr=subprocess.STDOUT) [sys.executable, idf_py_path, '-C%s' % current_dir, '--test-5=asdf'],
env=os.environ,
stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:
self.assertIn('Error: Option "test_5" is deprecated since v2.0 and was removed in v3.0.', self.assertIn(
e.output.decode('utf-8', 'ignore')) 'Error: Option "test_5" is deprecated since v2.0 and was removed in v3.0.',
e.output.decode('utf-8', 'ignore'))
def test_deprecation_messages(self): def test_deprecation_messages(self):
output = subprocess.check_output( output = subprocess.check_output(
@ -195,7 +211,8 @@ class TestDeprecations(unittest.TestCase):
'ta', 'ta',
'test-1', 'test-1',
], ],
env=os.environ, stderr=subprocess.STDOUT).decode('utf-8', 'ignore') env=os.environ,
stderr=subprocess.STDOUT).decode('utf-8', 'ignore')
self.assertIn('Warning: Option "test_sub_1" is deprecated and will be removed in future versions.', output) self.assertIn('Warning: Option "test_sub_1" is deprecated and will be removed in future versions.', output)
self.assertIn( self.assertIn(
@ -211,4 +228,4 @@ class TestDeprecations(unittest.TestCase):
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() main()