From 24f6d9ddca6d1a0daf5bf0bb904338c755eb1b72 Mon Sep 17 00:00:00 2001 From: Dave Dalcino Date: Sun, 20 Nov 2022 10:02:31 -0800 Subject: [PATCH] Add cli tests for long_modules and modules with archives This should cover the new lines of uncovered code in this PR. --- tests/test_install.py | 37 +++++++++++++++- tests/test_list.py | 99 +++++++++++++++++++++---------------------- 2 files changed, 85 insertions(+), 51 deletions(-) diff --git a/tests/test_install.py b/tests/test_install.py index f98d362..bd31df4 100644 --- a/tests/test_install.py +++ b/tests/test_install.py @@ -77,7 +77,7 @@ LIST_OF_FILES_AND_CONTENTS = Iterable[Dict[str, str]] class PatchedFile: filename: str unpatched_content: str - patched_content: Optional[str] + patched_content: Optional[str] = None # When None, the file is expected not to be patched. def expected_content(self, **kwargs) -> str: if not self.patched_content: @@ -349,6 +349,41 @@ def tool_archive(host: str, tool_name: str, variant: str, date: datetime = datet r"INFO : Time elapsed: .* second" ), ), + ( # Mixing --modules with --archives + "install-qt windows desktop 5.14.0 win32_mingw73 -m qtcharts --archives qtbase".split(), + "windows", + "desktop", + "5.14.0", + {"std": "win32_mingw73"}, + {"std": "mingw73_32"}, + {"std": "windows_x86/desktop/qt5_5140/Updates.xml"}, + { + "std": [ + plain_qtbase_archive("qt.qt5.5140.win32_mingw73", "win32_mingw73"), + MockArchive( + filename_7z="qtcharts-windows-win32_mingw73.7z", + update_xml_name="qt.qt5.5140.qtcharts.win32_mingw73", + contents=(PatchedFile(filename="lib/qtcharts.h", unpatched_content="... charts ...\n"),), + should_install=True, + ), + MockArchive( + filename_7z="qtlottie-windows-win32_mingw73.7z", + update_xml_name="qt.qt5.5140.qtlottie.win32_mingw73", + contents=(PatchedFile(filename="lib/qtlottie.h", unpatched_content="... lottie ...\n"),), + should_install=False, + ), + ] + }, + re.compile( + r"^INFO : aqtinstall\(aqt\) v.* on Python 3.*\n" + r"INFO : Downloading qtbase...\n" + r"Finished installation of qtbase-windows-win32_mingw73.7z in .*\n" + r"INFO : Downloading qtcharts...\n" + r"Finished installation of qtcharts-windows-win32_mingw73.7z in .*\n" + r"INFO : Finished installation\n" + r"INFO : Time elapsed: .* second" + ), + ), ( "install-src windows desktop 5.14.2".split(), "windows", diff --git a/tests/test_list.py b/tests/test_list.py index d431710..9877abd 100644 --- a/tests/test_list.py +++ b/tests/test_list.py @@ -865,65 +865,64 @@ def test_show_list_tools_long_ifw(capsys, monkeypatch, columns, expect): assert out == expect +LONG_MODULES_WIN_5140_120 = ( + " Module Name Display Name Release Date Download Size Installed Size\n" + "====================================================================================================================\n" + "qtcharts Qt Charts for MinGW 7.3.0 32-bit 2019-12-11 772.7K 7.8M \n" + "qtdatavis3d Qt Data Visualization for MinGW 7.3.0 32-bit 2019-12-11 620.2K 5.0M \n" + "qtlottie Qt Lottie Animation for MinGW 7.3.0 32-bit 2019-12-11 153.5K 968.4K \n" + "qtnetworkauth Qt Network Authorization for MinGW 7.3.0 32-bit 2019-12-11 98.7K 638.6K \n" + "qtpurchasing Qt Purchasing for MinGW 7.3.0 32-bit 2019-12-11 50.9K 306.8K \n" + "qtquick3d Qt Quick 3D for MinGW 7.3.0 32-bit 2019-12-11 9.8M 21.2M \n" + "qtquicktimeline Qt Quick Timeline for MinGW 7.3.0 32-bit 2019-12-11 35.3K 154.1K \n" + "qtscript Qt Script for MinGW 7.3.0 32-bit 2019-12-11 1.0M 5.5M \n" + "qtvirtualkeyboard Qt Virtual Keyboard for MinGW 7.3.0 32-bit 2019-12-11 2.1M 6.8M \n" + "qtwebglplugin Qt WebGL Streaming Plugin for MinGW 7.3.0 32-bit 2019-12-11 201.7K 1.0M \n" +) +LONG_MODULES_WIN_5140_80 = ( + " Module Name Display Name \n" + "====================================================================\n" + "qtcharts Qt Charts for MinGW 7.3.0 32-bit \n" + "qtdatavis3d Qt Data Visualization for MinGW 7.3.0 32-bit \n" + "qtlottie Qt Lottie Animation for MinGW 7.3.0 32-bit \n" + "qtnetworkauth Qt Network Authorization for MinGW 7.3.0 32-bit \n" + "qtpurchasing Qt Purchasing for MinGW 7.3.0 32-bit \n" + "qtquick3d Qt Quick 3D for MinGW 7.3.0 32-bit \n" + "qtquicktimeline Qt Quick Timeline for MinGW 7.3.0 32-bit \n" + "qtscript Qt Script for MinGW 7.3.0 32-bit \n" + "qtvirtualkeyboard Qt Virtual Keyboard for MinGW 7.3.0 32-bit \n" + "qtwebglplugin Qt WebGL Streaming Plugin for MinGW 7.3.0 32-bit\n" +) + + @pytest.mark.parametrize( - "columns, expect", + "columns, use_cli, expect", ( - ( - 120, - " Module Name Display Name Release Date Download Size " - "Installed Size\n" - "======================================================================================================" - "==============\n" - "qtcharts Qt Charts for MinGW 7.3.0 32-bit 2019-12-11 772.7K " - "7.8M \n" - "qtdatavis3d Qt Data Visualization for MinGW 7.3.0 32-bit 2019-12-11 620.2K " - "5.0M \n" - "qtlottie Qt Lottie Animation for MinGW 7.3.0 32-bit 2019-12-11 153.5K " - "968.4K \n" - "qtnetworkauth Qt Network Authorization for MinGW 7.3.0 32-bit 2019-12-11 98.7K " - "638.6K \n" - "qtpurchasing Qt Purchasing for MinGW 7.3.0 32-bit 2019-12-11 50.9K " - "306.8K \n" - "qtquick3d Qt Quick 3D for MinGW 7.3.0 32-bit 2019-12-11 9.8M " - "21.2M \n" - "qtquicktimeline Qt Quick Timeline for MinGW 7.3.0 32-bit 2019-12-11 35.3K " - "154.1K \n" - "qtscript Qt Script for MinGW 7.3.0 32-bit 2019-12-11 1.0M " - "5.5M \n" - "qtvirtualkeyboard Qt Virtual Keyboard for MinGW 7.3.0 32-bit 2019-12-11 2.1M " - "6.8M \n" - "qtwebglplugin Qt WebGL Streaming Plugin for MinGW 7.3.0 32-bit 2019-12-11 201.7K " - "1.0M \n", - ), - ( - 80, - " Module Name Display Name \n" - "====================================================================\n" - "qtcharts Qt Charts for MinGW 7.3.0 32-bit \n" - "qtdatavis3d Qt Data Visualization for MinGW 7.3.0 32-bit \n" - "qtlottie Qt Lottie Animation for MinGW 7.3.0 32-bit \n" - "qtnetworkauth Qt Network Authorization for MinGW 7.3.0 32-bit \n" - "qtpurchasing Qt Purchasing for MinGW 7.3.0 32-bit \n" - "qtquick3d Qt Quick 3D for MinGW 7.3.0 32-bit \n" - "qtquicktimeline Qt Quick Timeline for MinGW 7.3.0 32-bit \n" - "qtscript Qt Script for MinGW 7.3.0 32-bit \n" - "qtvirtualkeyboard Qt Virtual Keyboard for MinGW 7.3.0 32-bit \n" - "qtwebglplugin Qt WebGL Streaming Plugin for MinGW 7.3.0 32-bit\n", - ), + (120, False, LONG_MODULES_WIN_5140_120), + (80, False, LONG_MODULES_WIN_5140_80), + (120, True, LONG_MODULES_WIN_5140_120), + (80, True, LONG_MODULES_WIN_5140_80), ), ) -def test_show_list_long_qt_modules(capsys, monkeypatch, columns, expect): +def test_show_list_long_qt_modules(capsys, monkeypatch, columns: int, use_cli: bool, expect: str): update_xml = (Path(__file__).parent / "data" / "windows-5140-update.xml").read_text("utf-8") monkeypatch.setattr(MetadataFactory, "fetch_http", lambda self, _: update_xml) + cli = Cli() + + # Patching get_terminal_size prevents successful instantiation of Cli, so do it afterwards: monkeypatch.setattr(shutil, "get_terminal_size", lambda fallback: os.terminal_size((columns, 24))) - meta = MetadataFactory( - ArchiveId("qt", "windows", "desktop"), - modules_query=ModulesQuery("5.14.0", "win32_mingw73"), - is_long_listing=True, - ) - show_list(meta) + if use_cli: + return_code = cli.run("list-qt windows desktop --long-modules 5.14.0 win32_mingw73".split()) + assert return_code == 0 + else: + meta = MetadataFactory( + ArchiveId("qt", "windows", "desktop"), + modules_query=ModulesQuery("5.14.0", "win32_mingw73"), + is_long_listing=True, + ) + show_list(meta) out, err = capsys.readouterr() sys.stdout.write(out) sys.stderr.write(err)