Permalink
Browse files

Provide api level and compat to build (PR #9095)

* Introduce API versions
* Send APIVersion and APICompatTo to exbi
Data is sent with other JSON data in build variables.
  • Loading branch information...
feerrenrut committed Dec 20, 2018
1 parent 7e54d8b commit d7e98c05833b28bb2641fa938ed1b6f32ff2eca2
Showing with 93 additions and 0 deletions.
  1. +5 −0 appveyor.yml
  2. +35 −0 source/addonAPIVersion.py
  3. +53 −0 tests/unit/test_addonVersionCheck.py
@@ -179,10 +179,15 @@ deploy_script:
# Notify our server.
$exe = Get-ChildItem -Name output\*.exe
$hash = (Get-FileHash "output\$exe" -Algorithm SHA1).Hash.ToLower()
$apiVersion = (python -c "import sys; sys.path.append('source'); from addonAPIVersion import CURRENT; print('{}.{}.{}'.format(*CURRENT))")
echo apiversion: $apiVersion
$apiCompatTo = (python -c "import sys; sys.path.append('source'); from addonAPIVersion import BACK_COMPAT_TO; print('{}.{}.{}'.format(*BACK_COMPAT_TO))")
echo apiBackCompatTo: $apiCompatTo
$data = @{
jobId=$env:APPVEYOR_JOB_ID;
commit=$env:APPVEYOR_REPO_COMMIT;
version=$env:version; versionType=$env:versionType;
apiVersion=$apiVersion; apiCompatTo=$apiCompatTo;
avVersion=$env:APPVEYOR_BUILD_VERSION;
branch=$env:APPVEYOR_REPO_BRANCH;
exe=$exe; hash=$hash;
@@ -0,0 +1,35 @@
#A part of NonVisual Desktop Access (NVDA)
#Copyright (C) 2018 NV Access Limited
#This file is covered by the GNU General Public License.
#See the file COPYING for more details.

import buildVersion
import re

"""
This module contains add-on API version information for this build of NVDA. This file provides information on
how the API has changed as well as the range of API versions supported by this build of NVDA
"""

CURRENT = (buildVersion.version_year, buildVersion.version_major, buildVersion.version_minor)
BACK_COMPAT_TO = (0, 0, 0)
"""
As BACK_COMPAT_TO is incremented, the changed / removed parts / or reasoning should be added below.
EG: (x, y, z): Large changes to speech.py
---
(0, 0, 0): API version zero, used to signify addons released prior to API version checks.
"""

#: Compiled regular expression to match an addon API version string.
#: Supports year.month.minor versions (e.g. 2018.1.1).
#: Resulting match objects expose three groups reflecting release year, release month, and release minor version,
# respectively.
#: @type: RegexObject
ADDON_API_VERSION_REGEX = re.compile(r"^(\d{4})\.(\d)\.(\d)$")

def getAPIVersionTupleFromString(version):
"""Converts a string containing an NVDA version to a tuple of the form (versionYear, versionMajor, versionMinor)"""
match = ADDON_API_VERSION_REGEX.match(version)
if not match:
raise ValueError(version)
return tuple(int(i) if i is not None else 0 for i in match.groups())
@@ -7,6 +7,7 @@

import unittest

import addonAPIVersion
import versionInfo
from addonHandler import AddonBase
from addonHandler import addonVersionCheck
@@ -342,3 +343,55 @@ def test_setAddonCompatibility_untestedWithSupportToIncompatible_manuallySetInco
)
compat = self.mockStateSaver.getSavedState(notTestedAddon)
self.assertCompatValuesMatch(compat, compatValues.MANUALLY_SET_INCOMPATIBLE)


class TestGetAPIVersionTupleFromString(unittest.TestCase):

def test_getAPIVersionTupleFromString_succeeds(self):
"""Tests trying to get the API version tuple from an API version string with one matching group
results in an error being raised
"""
self.assertEqual((2019, 1, 0), addonAPIVersion.getAPIVersionTupleFromString("2019.1.0"))


def test_getAPIVersionTupleFromString_noGroupsMatch_raises(self):
"""Tests trying to get the API version tuple from an API version string with no matching groups
results in an error being raised
"""
self.assertRaises(ValueError, addonAPIVersion.getAPIVersionTupleFromString, "not valid")

def test_getAPIVersionTupleFromString_twoYearDigits_raises(self):
"""Tests trying to get the API version tuple from an API version string with not enough (2) digits
in the year part results in an error being raised
"""
self.assertRaises(ValueError, addonAPIVersion.getAPIVersionTupleFromString, "19.1.0")

def test_getAPIVersionTupleFromString_threeYearDigits_raises(self):
"""Tests trying to get the API version tuple from an API version string with not enough (3) digits
in the year part results in an error being raised
"""
self.assertRaises(ValueError, addonAPIVersion.getAPIVersionTupleFromString, "019.1.0")

def test_getAPIVersionTupleFromString_oneMatch_raises(self):
"""Tests trying to get the API version tuple from an API version string with one matching group
results in an error being raised
"""
self.assertRaises(ValueError, addonAPIVersion.getAPIVersionTupleFromString, "2019.")

def test_getAPIVersionTupleFromString_twoMatch_raises(self):
"""Tests trying to get the API version tuple from an API version string with two matching groups
results in an error being raised
"""
self.assertRaises(ValueError, addonAPIVersion.getAPIVersionTupleFromString, "2019.1")

def test_getAPIVersionTupleFromString_devAppended_raises(self):
"""Tests trying to get the API version tuple from an API version string with three matching groups
and some extra appended results in an error being raised
"""
self.assertRaises(ValueError, addonAPIVersion.getAPIVersionTupleFromString, "2019.1.0dev")

def test_getAPIVersionTupleFromString_devPrepended_raises(self):
"""Tests trying to get the API version tuple from an API version string with three matching groups
and some extra prepended results in an error being raised
"""
self.assertRaises(ValueError, addonAPIVersion.getAPIVersionTupleFromString, "dev2019.1.0")

0 comments on commit d7e98c0

Please sign in to comment.