I am creating a custom ComponentSetting that I want to access in a single test step. Is there a way to access the properties in an iterator-like manner?
There are approximately 25 settings, so accessing them without naming them individually is advantageous.
Example code of my attempts which produce errors:
def Run(self):
self.log.Info("Example setting is: {0}".format(OpenTap.ComponentSettings.GetCurrent(ReportSettings).AmbientTemperature))
self.log.Info(str(OpenTap.ComponentSettings.GetCurrent(ReportSettings).ToString()))
self.log.Info(str(OpenTap.ComponentSettings.GetDefaultOf(ReportSettings)))
I am not sure you can get a dict-like object, but it is possible to iterate the members. In the following example, a test step prints out all the (writable) members of a settings object.
example:
from opentap import *
from System import Int32, String, Boolean
from System.ComponentModel import Browsable, BrowsableAttribute
import OpenTap
from OpenTap import EnabledIf
from OpenTap import TypeData
from OpenTap import ComponentSettings
import System.Linq
from System.Linq import Enumerable
@attribute(OpenTap.Display("Example Settings", "A basic example of how to define settings."))
class SomeSettings(OpenTap.ComponentSettings):
def __init__(self):
super().__init__()
NumberOfPoints = property(Int32, 600)\
.add_attribute(OpenTap.Display("Number of points"))
NumberOfPoints2 = property(Int32, 6020)\
.add_attribute(OpenTap.Display("Number of points"))
@attribute(OpenTap.Display("Test Step Example", "A simple python test step", "PythonTest"))
class IterateMembersExample (TestStep):
def __init__(self):
super(IterateMembersExample, self).__init__()
def Run(self):
settings = SomeSettings.GetCurrent(SomeSettings)
for member in TypeData.GetTypeData(settings).GetMembers():
if not member.Writable:
continue
self.log.Info("member {0}: {1} {2}", member, member.TypeDescriptor, member.GetValue(settings))