Addon Manager: Add tests for Addon

This commit is contained in:
Chris Hennes
2022-02-27 23:32:33 -06:00
parent 0d6a506447
commit 96006c7587
5 changed files with 106 additions and 1 deletions

View File

@@ -0,0 +1,79 @@
# -*- coding: utf-8 -*-
# ***************************************************************************
# * Copyright (c) 2022 FreeCAD Project Association *
# * *
# * This file is part of the FreeCAD CAx development system. *
# * *
# * This library is free software; you can redistribute it and/or *
# * modify it under the terms of the GNU Lesser General Public *
# * License as published by the Free Software Foundation; either *
# * version 2.1 of the License, or (at your option) any later version. *
# * *
# * This library is distributed in the hope that it will be useful, *
# * but WITHOUT ANY WARRANTY; without even the implied warranty of *
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
# * Lesser General Public License for more details. *
# * *
# * You should have received a copy of the GNU Lesser General Public *
# * License along with this library; if not, write to the Free Software *
# * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA *
# * 02110-1301 USA *
# * *
# ***************************************************************************
import unittest
import os
import FreeCAD
from Addon import Addon
class TestAddon(unittest.TestCase):
MODULE = "test_addon" # file name without extension
def setUp(self):
self.test_dir = os.path.join(FreeCAD.getHomePath(), "Mod", "AddonManager", "AddonManagerTest", "data")
def test_display_name(self):
# Case 1: No display name set elsewhere: name == display_name
addon = Addon("FreeCAD","https://github.com/FreeCAD/FreeCAD", Addon.Status.NOT_INSTALLED, "master")
self.assertEqual(addon.name, "FreeCAD")
self.assertEqual(addon.display_name, "FreeCAD")
# Case 2: Package.xml metadata file sets a display name:
addon.load_metadata_file(os.path.join(self.test_dir, "good_package.xml"))
self.assertEqual(addon.name, "FreeCAD")
self.assertEqual(addon.display_name, "Test Workbench")
def test_metadata_loading(self):
addon = Addon("FreeCAD","https://github.com/FreeCAD/FreeCAD", Addon.Status.NOT_INSTALLED, "master")
addon.load_metadata_file(os.path.join(self.test_dir, "good_package.xml"))
# Generic tests:
self.assertIsNotNone(addon.metadata)
self.assertEqual(addon.metadata.Version, "1.0.1")
self.assertEqual(addon.metadata.Description, "A package.xml file for unit testing.")
maintainer_list = addon.metadata.Maintainer
self.assertEqual(len(maintainer_list),1,"Wrong number of maintainers found")
self.assertEqual(maintainer_list[0]["name"],"FreeCAD Developer")
self.assertEqual(maintainer_list[0]["email"],"developer@freecad.org")
license_list = addon.metadata.License
self.assertEqual(len(license_list),1,"Wrong number of licenses found")
self.assertEqual(license_list[0]["name"],"LGPLv2.1")
self.assertEqual(license_list[0]["file"],"LICENSE")
url_list = addon.metadata.Urls
self.assertEqual(len(url_list),2,"Wrong number of urls found")
self.assertEqual(url_list[0]["type"],"repository")
self.assertEqual(url_list[0]["location"],"https://github.com/chennes/FreeCAD-Package")
self.assertEqual(url_list[0]["branch"],"main")
self.assertEqual(url_list[1]["type"],"readme")
self.assertEqual(url_list[1]["location"],"https://github.com/chennes/FreeCAD-Package/blob/main/README.md")
contents = addon.metadata.Content
self.assertEqual(len(contents),1,"Wrong number of content catetories found")
self.assertEqual(len(contents["workbench"]),1,"Wrong number of workbenches found")

View File

@@ -115,7 +115,7 @@ class TestUtilities(unittest.TestCase):
]
for line in good_lines:
result = get_assigned_string_literal(line[0])
self.assertEquals(result, line[1])
self.assertEqual(result, line[1])
bad_lines = [
"my_var = __date__",

View File

@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8" standalone="no" ?>
<package format="1" xmlns="https://wiki.freecad.org/Package_Metadata">
<name>Test Workbench</name>
<description>A package.xml file for unit testing.</description>
<version>1.0.1</version>
<date>2022-01-07</date>
<maintainer email="developer@freecad.org">FreeCAD Developer</maintainer>
<license file="LICENSE">LGPLv2.1</license>
<url type="repository" branch="main">https://github.com/chennes/FreeCAD-Package</url>
<url type="readme">https://github.com/chennes/FreeCAD-Package/blob/main/README.md</url>
<icon>Resources/icons/PackageIcon.svg</icon>
<content>
<workbench>
<classname>MyWorkbench</classname>
<subdirectory>./</subdirectory>
</workbench>
</content>
</package>

View File

@@ -42,6 +42,7 @@ SET(AddonManagerTests_SRCS
SET(AddonManagerTestsApp_SRCS
AddonManagerTest/app/__init__.py
AddonManagerTest/app/test_utilities.py
AddonManagerTest/app/test_addon.py
)
SET(AddonManagerTestsGui_SRCS
@@ -54,6 +55,7 @@ SET(AddonManagerTestsFiles_SRCS
AddonManagerTest/data/bad_macro_metadata.FCStd
AddonManagerTest/data/good_macro_metadata.FCStd
AddonManagerTest/data/missing_macro_metadata.FCStd
AddonManagerTest/data/good_package.xml
)
SET(AddonManagerTests_ALL

View File

@@ -26,6 +26,10 @@
from AddonManagerTest.app.test_utilities import (
TestUtilities as AddonManagerTestUtilities,
)
from AddonManagerTest.app.test_addon import (
TestAddon as AddonManagerTestAddon,
)
# dummy usage to get flake8 and lgtm quiet
False if AddonManagerTestUtilities.__name__ else True
False if AddonManagerTestAddon.__name__ else True