mirror of
https://github.com/BOSWatch/BW3-Core.git
synced 2025-12-06 07:12:04 +01:00
edit descriptor and his test
This commit is contained in:
parent
bf6777d095
commit
b275abd86f
|
|
@ -34,29 +34,40 @@ class Descriptor:
|
||||||
def loadDescription(self, csvType):
|
def loadDescription(self, csvType):
|
||||||
"""!Build a new description list
|
"""!Build a new description list
|
||||||
|
|
||||||
@param csvType: Name of the CSV file without `.csv`"""
|
@param csvType: Name of the CSV file without `.csv`
|
||||||
self._lists[csvType] = DescriptionList(csvType)
|
@return True or False"""
|
||||||
|
bwDescriptionList = DescriptionList()
|
||||||
|
if bwDescriptionList.loadCSV(csvType):
|
||||||
|
self._lists[csvType] = bwDescriptionList
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
def addDescriptions(self, bwPacket):
|
def addDescriptions(self, bwPacket):
|
||||||
"""!Add the short and long description to a bwPacket
|
"""!Add the short and long description to a bwPacket
|
||||||
|
|
||||||
@param bwPacket: bwPacket instance to add descriptions"""
|
@param bwPacket: bwPacket instance to add descriptions
|
||||||
|
@return True or False"""
|
||||||
logging.debug("add descriptions to bwPacket")
|
logging.debug("add descriptions to bwPacket")
|
||||||
bwPacket.setField("shortDescription",
|
try:
|
||||||
self._lists[bwPacket.getField("mode")].getShortDescription(bwPacket.getField(bwPacket.getField("mode"))))
|
bwPacket.setField("shortDescription",
|
||||||
|
self._lists[bwPacket.getField("mode")].getShortDescription(bwPacket.getField(bwPacket.getField("mode"))))
|
||||||
|
|
||||||
bwPacket.setField("longDescription",
|
bwPacket.setField("longDescription",
|
||||||
self._lists[bwPacket.getField("mode")].getLongDescription(bwPacket.getField(bwPacket.getField("mode"))))
|
self._lists[bwPacket.getField("mode")].getLongDescription(bwPacket.getField(bwPacket.getField("mode"))))
|
||||||
|
return True
|
||||||
|
except:
|
||||||
|
logging.exception("error while adding descriptions")
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
class DescriptionList:
|
class DescriptionList:
|
||||||
def __init__(self, csvType):
|
def __init__(self): # , csvType):
|
||||||
"""!Loads the given CSV file into internal list
|
"""!Loads the given CSV file into internal list
|
||||||
|
|
||||||
@param csvType: Name of the CSV file without `.csv`"""
|
@param csvType: Name of the CSV file without `.csv`"""
|
||||||
logging.debug("create new descriptionList")
|
logging.debug("create new descriptionList")
|
||||||
self._descriptionList = {}
|
self._descriptionList = {}
|
||||||
self._loadCSV(csvType)
|
# self.loadCSV(csvType)
|
||||||
|
|
||||||
def getShortDescription(self, id):
|
def getShortDescription(self, id):
|
||||||
"""!Returns the short description of given id
|
"""!Returns the short description of given id
|
||||||
|
|
@ -76,13 +87,7 @@ class DescriptionList:
|
||||||
except:
|
except:
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
def _getFullList(self):
|
def loadCSV(self, csvType):
|
||||||
"""!Returns the full intern _descriptionList
|
|
||||||
|
|
||||||
@return descriptionList as dict"""
|
|
||||||
return self._descriptionList
|
|
||||||
|
|
||||||
def _loadCSV(self, csvType):
|
|
||||||
"""!Load descriptions from an csv file
|
"""!Load descriptions from an csv file
|
||||||
|
|
||||||
@param csvType: Name of the CSV file without `.csv`
|
@param csvType: Name of the CSV file without `.csv`
|
||||||
|
|
|
||||||
|
|
@ -15,21 +15,53 @@
|
||||||
@description: Unittests for BOSWatch. File must be run as "pytest" unittest
|
@description: Unittests for BOSWatch. File must be run as "pytest" unittest
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
# import pytest # import the pytest framework
|
# import pytest # import the pytest framework
|
||||||
|
|
||||||
from boswatch.descriptor import descriptor
|
from boswatch.descriptor import descriptor
|
||||||
|
from boswatch.packet import packet
|
||||||
|
|
||||||
|
|
||||||
class Test_Descriptor:
|
class Test_Descriptor:
|
||||||
"""!Unittests for the descriptor"""
|
"""!Unittests for the descriptor"""
|
||||||
|
|
||||||
def test_loadCSVnotExist(self):
|
def test_loadCSVnotExist(self):
|
||||||
"""!read CSV file where not exist"""
|
"""!read CSV file where not exist direct per DescriptionList class"""
|
||||||
descList = descriptor.DescriptionList("boswatch")
|
descList = descriptor.DescriptionList()
|
||||||
assert bool(descList._getFullList()) is False
|
assert descList.loadCSV("boswatch") is False
|
||||||
|
|
||||||
def test_loadCSV(self):
|
def test_loadCSV(self):
|
||||||
|
"""!read CSV file direct per DescriptionList class"""
|
||||||
|
descList = descriptor.DescriptionList()
|
||||||
|
assert descList.loadCSV("zvei") is True
|
||||||
|
|
||||||
|
def test_descriptorLoadFailed(self):
|
||||||
|
"""!read CSV file where not exist"""
|
||||||
|
bwDescriptor = descriptor.Descriptor()
|
||||||
|
assert bwDescriptor.loadDescription("boswatch") is False
|
||||||
|
|
||||||
|
def test_descriptorLoad(self):
|
||||||
"""!read CSV file"""
|
"""!read CSV file"""
|
||||||
descList = descriptor.DescriptionList("zvei")
|
bwDescriptor = descriptor.Descriptor()
|
||||||
assert bool(descList._getFullList()) is True
|
assert bwDescriptor.loadDescription("zvei") is True
|
||||||
|
|
||||||
|
def test_loadDescriptionsNotSet(self):
|
||||||
|
"""!load descriptions where not set to an bwPacket"""
|
||||||
|
bwDescriptor = descriptor.Descriptor()
|
||||||
|
assert bwDescriptor.loadDescription("zvei") is True
|
||||||
|
bwPacket = packet.Packet()
|
||||||
|
bwPacket.setField("mode", "zvei")
|
||||||
|
bwPacket.setField("zvei", "54321")
|
||||||
|
assert bwDescriptor.addDescriptions(bwPacket) is True
|
||||||
|
assert bwPacket.getField("shortDescription") is ""
|
||||||
|
assert bwPacket.getField("longDescription") is ""
|
||||||
|
|
||||||
|
def test_loadDescriptions(self):
|
||||||
|
"""!load descriptions to an bwPacket"""
|
||||||
|
bwDescriptor = descriptor.Descriptor()
|
||||||
|
assert bwDescriptor.loadDescription("zvei") is True
|
||||||
|
bwPacket = packet.Packet()
|
||||||
|
bwPacket.setField("mode", "zvei")
|
||||||
|
bwPacket.setField("zvei", "12345")
|
||||||
|
assert bwDescriptor.addDescriptions(bwPacket) is True
|
||||||
|
assert bwPacket.getField("shortDescription") is not ""
|
||||||
|
assert bwPacket.getField("longDescription") is not ""
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue