def test_simple_rmqres(config, test_resources): runner = CliRunner() # Generate a qrc file named res and update config file runner.invoke(pyqtcli, ["new", "qrc"]) # Add resources folder config file and qrc runner.invoke(pyqtcli, ["addqres", "res.qrc", "resources"]) # Remove resources folder config file and qrc result = runner.invoke(pyqtcli, ["rmqres", "res.qrc", "resources", "-v"]) # Parse qrc file qrcfile = read_qrc("res.qrc") # Check qresource has been deleted with pytest.raises(QresourceError) as e: qrcfile.get_qresource("/resources") assert format_msg(str(e.value)) == ( "Error: No <qresource> node corresponding to '/resources' prefix" ) # Check res_folder has been removed from dirs variable of config file config.read() assert config.get_dirs("res.qrc") == [] assert format_msg(result.output) == v.info( "Resources folder: \'resources\' has been removed in res.qrc.\n" )
def test_addqres_in_non_project_qrc(config, test_resources): runner = CliRunner() QRCTestFile("res").add_qresource("/").add_file("test.txt").build() result = runner.invoke(pyqtcli, ["addqres", "res.qrc", "resources"]) assert format_msg(result.output) == v.error("res.qrc isn't part of the project.\nAborted!\n")
def test_new_duplication(): runner = CliRunner() runner.invoke(pyqtcli, ["new", "qrc"]) result = runner.invoke(pyqtcli, ["new", "qrc"]) assert format_msg(result.output).startswith( "[ERROR]: A qrc file named \'res.qrc\' already exists" )
def test_makerc_with_invalid_qrc_file(): runner = CliRunner() open("invalid.qrc", "a").close() result = runner.invoke(pyqtcli, ["makerc", "-v", "invalid.qrc"]) assert format_msg(result.output) == ( "[WARNING]: Qrc file: \'invalid.qrc\' is not valid.\n")
def test_rmqres_with_non_recorded_res_folder(config, test_resources): runner = CliRunner() runner.invoke(pyqtcli, ["new", "qrc"]) result = runner.invoke(pyqtcli, ["rmqres", "res.qrc", "resources"]) assert format_msg(result.output) == v.warning( "There is no recorded resources folders to delete in res.qrc\n" )
def test_makerc_with_empty_qrc_file(): runner = CliRunner() QRCTestFile("res.qrc").build() result = runner.invoke(pyqtcli, ["makerc", "res.qrc"]) assert format_msg(result.output) == ( "[WARNING]: res.qrc has no more resources and cannot " "generates its corresponding rc file.\n" )
def test_addqres_duplication(config, test_resources): runner = CliRunner() # Generate a qrc file named res and update config file runner.invoke(pyqtcli, ["new", "qrc"]) # Add qresources corresponding to resources folder runner.invoke(pyqtcli, ["addqres", "res.qrc", "resources"]) # Add the same qresource result = runner.invoke(pyqtcli, ["addqres", "res.qrc", "resources"]) assert format_msg(result.output) == v.warning("You have already added 'resources' to res.qrc.\n")
def test_rmqres_with_multiple_res_folders_separately(config, test_resources): runner = CliRunner() # Copy resources dir to make another resource folder in another directory os.mkdir("test") shutil.copytree("resources", "test/other_res") # Generate a qrc file named res and update config file runner.invoke(pyqtcli, ["new", "qrc"]) # Add resources folder config file and qrc runner.invoke( pyqtcli, ["addqres", "res.qrc", "resources", "test/other_res"]) # Remove resources folder config file and qrc runner.invoke(pyqtcli, ["rmqres", "res.qrc", "resources"]) runner.invoke(pyqtcli, ["rmqres", "res.qrc", "test/other_res"]) # Parse qrc file qrcfile = read_qrc("res.qrc") # Check qresources has been deleted with pytest.raises(QresourceError) as e: qrcfile.get_qresource("/resource") assert format_msg(str(e.value)) == ( "Error: No <qresource> node corresponding to '/resource' prefix" ) # Check qresources has been deleted with pytest.raises(QresourceError) as e: qrcfile.get_qresource("/other_res") assert format_msg(str(e.value)) == ( "Error: No <qresource> node corresponding to '/other_res' prefix" ) # Check res_folder has been removed from dirs variable of config file config.read() assert config.get_dirs("res.qrc") == []
def test_delete_recorded_and_not_recorded_res_folders(config, test_resources): shutil.copytree("resources", "test") runner = CliRunner() # Generate a qrc file named res and update config file runner.invoke(pyqtcli, ["new", "qrc"]) # Test addqres with default option runner.invoke(pyqtcli, ["addqres", "res.qrc", "resources"]) # Remove resources folder config file and qrc result = runner.invoke(pyqtcli, ["rmqres", "res.qrc", "test"]) assert format_msg(result.output) == v.warning( ( "Directory 'test' isn't recorded for 'res.qrc' and so " "cannot be deleted\n" ) )
def test_new_default(config): runner = CliRunner() result = runner.invoke(pyqtcli, ["new", "qrc", "-v"]) # Check qrc file is generated assert result.exit_code == 0 assert os.path.isfile("res.qrc") # Check content of newly generated qrc file tree = etree.parse("res.qrc") assert etree.tostring(tree) == b"<RCC/>" # Check qrc file has been added to project the config file config.read() assert ["res.qrc"] == config.get_qrcs() # Test verbose assert format_msg(result.output) == v.info( "Qrc file \'res.qrc\' has been created.\n")