Beispiel #1
0
	def set_nmt_state(self, requested_state):
		logger.info('Requested NMT state: {}'.format(requested_state))
		assert_not_none(self._active_node, 'No node has been selected')
		state = requested_state.upper()  # Only uppercase letters are accepted
		self._active_node.nmt.state = state
		self._active_node.nmt.wait_for_heartbeat()  # To confirm the NMT command, wait for response
		assert_equal(self.get_current_nmt_state(), state)
def check_blacklist_table_from_logBlacklistInfoJournal(log, **kwargs):
    blacklistinfo = TbBlacklistInfo.find_by_slf_data(log.SLF_Data)
    assert_not_none(
        blacklistinfo,
        "cant find tb_blacklistinfo with slf_data=%s" % log.SLF_Data)
    assert_equal(log.EntityID, blacklistinfo.EntityID)
    assert_equal(str(log.SLF_Type), str(blacklistinfo.SLF_Type))
    assert_equal(str(log.SLF_RiskLevel), str(blacklistinfo.SLF_RiskLevel))
    assert_equal(str(log.SourceType), str(blacklistinfo.SourceType))
    assert_equal(str(log.SLF_ExpireDateTimeStamp),
                 str(blacklistinfo.SLF_ExpireDateTimeStamp))
    assert_equal(str(log.SLF_URLCorrelationKey),
                 str(blacklistinfo.SLF_URLCorrelationKey))
    assert_equal(log.FilterCRC, blacklistinfo.FilterCRC)

    for column, value in kwargs.items():
        if column == 'HasAssessed':
            value = 'True' if value == 1 else 'False'
        assert_equal(
            str(getattr(blacklistinfo, column)), str(value),
            "(Data %s)TbBlacklistInfo.%s should be %s, but is %s" %
            (blacklistinfo.SLF_Data, column, value,
             getattr(blacklistinfo, column)))
    check_blacklistextrainfo_from_logBlacklistInfoJournal(log, blacklistinfo)
    check_blacklistInfoRESTJournal_from_blacklistinfo(blacklistinfo)
Beispiel #3
0
 def _get_lib_and_instance(self, name):
     lib = TestLibrary(name)
     if lib.scope.is_global:
         assert_not_none(lib._libinst)
     else:
         assert_none(lib._libinst)
     return lib, lib._libinst
 def test_none_encoding(self):
     sys.__stdout__ = StreamStub(None)
     sys.__stderr__ = StreamStub(None)
     sys.__stdin__ = StreamStub('ascii')
     assert_equals(get_output_encoding(), self._get_encoding('ascii'))
     sys.__stdin__ = StreamStub(None)
     assert_not_none(get_output_encoding())
 def _test_format_change(self, to_format):
     controller = self._get_file_controller(MINIMAL_SUITE_PATH)
     assert_not_none(controller)
     controller.save_with_new_format(to_format)
     self._assert_removed(MINIMAL_SUITE_PATH)
     path_with_tsv = os.path.splitext(MINIMAL_SUITE_PATH)[0] + '.'+to_format
     self._assert_serialized(path_with_tsv)
 def _test_format_change(self, to_format):
     controller = self._get_file_controller(MINIMAL_SUITE_PATH)
     assert_not_none(controller)
     controller.save_with_new_format(to_format)
     self._assert_removed(MINIMAL_SUITE_PATH)
     path_with_tsv = os.path.splitext(MINIMAL_SUITE_PATH)[0] + '.'+to_format
     self._assert_serialized(path_with_tsv)
 def test_none_encoding(self):
     sys.__stdout__ = StreamStub(None)
     sys.__stderr__ = StreamStub(None)
     sys.__stdin__ = StreamStub('ascii')
     assert_equal(get_console_encoding(), 'ascii')
     sys.__stdin__ = StreamStub(None)
     assert_not_none(get_console_encoding())
    def add_port(self, port_locator, open=True, make_current=False, **kwargs):
        """
        Adds new port with specified locator.

        port_locator may be in (traditional) port name or url format.
        If `open` has false value, the port is closed immediately.
        Parameters given in kwargs will override those library defaults
        initialized on import.
        If make_current has truth value, the opened port is set to current
        port. Note that if there's only one port in the library instance,
        it will always be current port, regardless of make_current's value.

        Fails if specified port_locator is already used in this library
        instance.

        Returns created port instance.
        """
        if port_locator in [None, '', '_']:
            asserts.fail('Invalid port locator.')
        elif port_locator in self._ports:
            asserts.fail('Port already exists.')
        serial_kw = dict(
            (k, type(v)(kwargs.get(k, v))) for k, v in self._defaults.items())
        # try url first, then port name
        try:
            port = serial_for_url(port_locator, **serial_kw)
        except (AttributeError, ValueError):
            port = Serial(port_locator, **serial_kw)
        asserts.assert_not_none(port, 'Port initialization failed.')
        self._ports[port_locator] = port
        if port.is_open and (is_truthy(open) is False):
            port.close()
        if self._current_port_locator is None or make_current:
            self._current_port_locator = port_locator
        return port
Beispiel #9
0
 def test_none_encoding(self):
     sys.__stdout__ = StreamStub(None)
     sys.__stderr__ = StreamStub(None)
     sys.__stdin__ = StreamStub('ascii')
     assert_equal(get_console_encoding(), 'ascii')
     sys.__stdin__ = StreamStub(None)
     assert_not_none(get_console_encoding())
Beispiel #10
0
 def test_none_encoding(self):
     sys.__stdout__ = StreamStub(None)
     sys.__stderr__ = StreamStub(None)
     sys.__stdin__ = StreamStub('ascii')
     assert_equals(get_output_encoding(), self._get_encoding('ascii'))
     sys.__stdin__ = StreamStub(None)
     assert_not_none(get_output_encoding())
Beispiel #11
0
 def test_no_encoding(self):
     sys.__stdout__ = object()
     sys.__stderr__ = object()
     sys.__stdin__ = StreamStub('ascii')
     assert_equals(get_output_encoding(), 'ascii')
     sys.__stdin__ = object()
     assert_not_none(get_output_encoding())
 def test_no_encoding(self):
     sys.__stdout__ = object()
     sys.__stderr__ = object()
     sys.__stdin__ = StreamStub('ascii')
     assert_equals(get_output_encoding(), 'ascii')
     sys.__stdin__ = object()
     assert_not_none(get_output_encoding())
Beispiel #13
0
 def test_global_dynamic_handlers(self):
     lib = TestLibrary("RunKeywordLibrary.GlobalRunKeywordLibrary")
     assert_equal(len(lib.handlers), 2)
     for name in 'Run Keyword That Passes', 'Run Keyword That Fails':
         handler = lib.handlers[name]
         assert_not_none(handler._method)
         assert_not_equal(handler._method, lib._libinst.run_keyword)
         assert_equal(handler._method.__name__, 'handler')
 def test_get_timestamp(self):
     for seps, pattern in [((), '^\d{8} \d\d:\d\d:\d\d.\d\d\d$'),
                           (('',' ',':',None), '^\d{8} \d\d:\d\d:\d\d$'),
                           (('','','',None), '^\d{14}$'),
                           (('-',' ',':',';'),
                            '^\d{4}-\d\d-\d\d \d\d:\d\d:\d\d;\d\d\d$')]:
         ts = get_timestamp(*seps)
         assert_not_none(re.search(pattern, ts),
                         "'%s' didn't match '%s'" % (ts, pattern), False)
 def test_get_timestamp(self):
     for seps, pattern in [((), '^\d{8} \d\d:\d\d:\d\d.\d\d\d$'),
                           (('',' ',':',None), '^\d{8} \d\d:\d\d:\d\d$'),
                           (('','','',None), '^\d{14}$'),
                           (('-',' ',':',';'),
                            '^\d{4}-\d\d-\d\d \d\d:\d\d:\d\d;\d\d\d$')]:
         ts = get_timestamp(*seps)
         assert_not_none(re.search(pattern, ts),
                         "'%s' didn't match '%s'" % (ts, pattern), False)
Beispiel #16
0
 def test_is_user_keyword_in_resource_file(self):
     everything_tcf = TestCaseFile(
         source=TESTCASEFILE_WITH_EVERYTHING).populate()
     assert_not_none(
         self.ns.find_user_keyword(everything_tcf, 'Duplicate UK'))
     assert_true(self.ns.is_user_keyword(everything_tcf, 'Duplicate UK'))
     assert_not_none(
         self.ns.find_user_keyword(everything_tcf, 'Another Resource UK'))
     assert_true(
         self.ns.is_user_keyword(everything_tcf, 'Another Resource UK'))
    def current_port_should_be_regexp(self, port_locator_regexp):
        """
        Fails if given regexp does not match current port locator.

        If current port is None, it will only match to empty sring.
        Matching is case-insensitive.
        """
        current_port_locator = self._current_port_locator
        if current_port_locator is None:
            current_port_locator = ''
        regexp = re.compile(port_locator_regexp, re.I)
        asserts.assert_not_none(regexp.match(current_port_locator),
                                'Port does not match.',
                                values=False)
    def current_port_should_be_regexp(self, port_locator_regexp):
        """
        Fails if given regexp does not match current port locator.

        If current port is None, it will only match to empty sring.
        Matching is case-insensitive.
        """
        current_port_locator = self._current_port_locator
        if current_port_locator is None:
            current_port_locator = ''
        regexp = re.compile(port_locator_regexp, re.I)
        asserts.assert_not_none(
            regexp.match(current_port_locator),
            'Port does not match.', values=False)
Beispiel #19
0
	def sdo_read(self, index, subindex=0):
		assert_not_none(self._active_node, 'No node has been selected')
		if isinstance(index, str):
			index = int(index, 16)  # Convert string to 16-base integer
		try:
			if subindex == 0:
				logger.info('Read SDO: {}. Value: {:04x}'.format(hex(index), self._active_node.sdo[index].raw))
				return self._active_node.sdo[index].raw
			else:
				logger.info('Read SDO: {}:{}. Value: {:04x}'.format(hex(index), bin(subindex), self._active_node.sdo[index][subindex].raw))
				return self._active_node.sdo[index][subindex].raw
		except canopen.sdo.exceptions.SdoAbortedError:
			logger.error('Resource not available')
		except canopen.sdo.exceptions.SdoCommunicationError:
			logger.error('No or unexcpected response from slave')
Beispiel #20
0
	def sdo_write(self, value, index, subindex=0):
		assert_not_none(self._active_node, 'No node has been selected')
		if isinstance(index, str):
			index = int(index, 16)  # Convert string to 16-base integer
		try:
			if subindex == 0:
				logger.info('Write SDO: {}. Value: {:04x}'.format(hex(index), value))
				self._active_node.sdo[index].raw = value
				assert_equal(self._active_node.sdo[index].raw, value)
			else:
				logger.info('Write SDO: {}:{}. Value: {:04x}'.format(hex(index), bin(subindex), value))
				self._active_node.sdo[index][subindex].raw = value
				assert_equal(self._active_node.sdo[index][subindex].raw, value)
		except canopen.sdo.exceptions:
			logger.error('Failed writing to SDO.')
Beispiel #21
0
def check_quick_inv_match_obj_from_quick_inv_task(quick_inv_task, agent,
                                                  no_rca):
    match_agent = TbQuickInvMatchObjectInfo.find_by_slf_key_and_agent(
        quick_inv_task.SLF_Key, agent)
    assert_not_none(match_agent, "agent %s should exist" % agent)
    assert_equal(match_agent.RetroScanData_MD5,
                 quick_inv_task.RetroScanData_MD5,
                 "RetroScanData_MD5 should be the same")
    assert_equal(match_agent.RetroScanCategory,
                 quick_inv_task.RetroScanCategory,
                 "RetroScanCategory should be the same")
    if no_rca:
        assert_none(
            match_agent.RCAScanID,
            "RCAScanID should be NULL when RCA return no affected or yet to run RCA"
        )
Beispiel #22
0
def check_finished_rca_result(criteria,
                              agent,
                              status=4,
                              affected=1,
                              sync=1,
                              skip_match_obj=False):
    rca_agent = TbRCATask.find_by_criteria_and_agent(criteria, agent)
    assert_not_none(rca_agent.TaskID, "TaskID should not be Null")
    assert_not_none(rca_agent.ScanSummaryID,
                    "ScanSummaryID should not be Null")
    assert_equal(rca_agent.Status, int(status), "status should be %s" % status)
    assert_equal(rca_agent.IsAffected, int(affected),
                 "IsAffected should be %s" % affected)
    assert_equal(rca_agent.IsSync, int(sync), "IsSync should be %s" % sync)
    if not skip_match_obj:
        check_quick_inv_match_obj_from_rca_task(rca_agent, agent)
Beispiel #23
0
def check_init_rca_result(criteria, criteria_type, agents):
    agents = agents.split(',')
    for index in range(0, len(agents)):
        rca_agent = TbRCATask.find_by_criteria_and_agent(
            criteria, agents[index])
        assert_not_none(rca_agent,
                        "RCA record for agent %s should exist" % agents[index])
        assert_equal(rca_agent.CriteriaType, int(criteria_type),
                     "RCA criteriaType should be %s" % criteria_type)
        assert_none(rca_agent.TaskID, "RCA TaskID should not be NULL")
        assert_none(rca_agent.ScanSummaryID,
                    "RCA ScanSummaryID should not be NULL")
        assert_equal(rca_agent.Status, 0,
                     "RCA status should be 0 for init value")
        assert_equal(rca_agent.IsAffected, 0,
                     "RCA IsAffected should be 0 for init value")
        assert_equal(rca_agent.IsSync, 0,
                     "RCA IsSync should be 0 for init value")
    def add_port(self, port_locator, open=True, make_current=False, **kwargs):
        """
        Adds new port with specified locator.

        port_locator may be in (traditional) port name or url format.
        If `open` has false value, the port is closed immediately.
        Parameters given in kwargs will override those library defaults
        initialized on import.
        If make_current has truth value, the opened port is set to current
        port. Note that if there's only one port in the library instance,
        it will always be current port, regardless of make_current's value.

        Fails if specified port_locator is already used in this library
        instance.

        Returns created port instance.
        """
        if port_locator in [None, '', '_']:
            asserts.fail('Invalid port locator.')
        elif port_locator in self._ports:
            asserts.fail('Port already exists.')
        serial_kw = dict(
            (k, type(v)(kwargs.get(k, v)))
            for k, v in self._defaults.items())
        # try url first, then port name
        try:
            port = serial_for_url(port_locator, **serial_kw)
        except (AttributeError, ValueError):
            port = Serial(port_locator, **serial_kw)
        asserts.assert_not_none(port, 'Port initialization failed.')
        self._ports[port_locator] = port
        if port.is_open and (is_truthy(open) is False):
            port.close()
        if self._current_port_locator is None or make_current:
            self._current_port_locator = port_locator
        return port
Beispiel #25
0
 def test_given_when_then_and_aliases(self):
     assert_not_none(
         self.ns.find_user_keyword(
             self.tcf,
             '  Given   UK Fromresource from rESOURCE with variaBLE'))
     assert_not_none(
         self.ns.find_user_keyword(
             self.tcf, 'when  UK Fromresource from rESOURCE with variaBLE'))
     assert_not_none(
         self.ns.find_user_keyword(
             self.tcf,
             '  then UK Fromresource from rESOURCE with variaBLE'))
     assert_not_none(
         self.ns.find_user_keyword(
             self.tcf, 'AND UK Fromresource from rESOURCE with variaBLE'))
     assert_none(
         self.ns.find_user_keyword(
             self.tcf,
             'given and UK Fromresource from rESOURCE with variaBLE'))
 def test_get_env_var(self):
     assert_not_none(get_env_var('PATH'))
     assert_equal(get_env_var(TEST_VAR), TEST_VAL)
     assert_none(get_env_var('NoNeXiStInG'))
     assert_equal(get_env_var('NoNeXiStInG', 'default'), 'default')
Beispiel #27
0
 def test_is_user_keyword_in_resource_file(self):
     everything_tcf = TestCaseFile(source=TESTCASEFILE_WITH_EVERYTHING).populate()
     assert_not_none(self.ns.find_user_keyword(everything_tcf, 'Duplicate UK'))
     assert_true(self.ns.is_user_keyword(everything_tcf, 'Duplicate UK'))
     assert_not_none(self.ns.find_user_keyword(everything_tcf, 'Another Resource UK'))
     assert_true(self.ns.is_user_keyword(everything_tcf, 'Another Resource UK'))
Beispiel #28
0
 def test_given_when_then_and_aliases(self):
     assert_not_none(self.ns.find_user_keyword(self.tcf, '  Given   UK Fromresource from rESOURCE with variaBLE'))
     assert_not_none(self.ns.find_user_keyword(self.tcf, 'when  UK Fromresource from rESOURCE with variaBLE'))
     assert_not_none(self.ns.find_user_keyword(self.tcf, '  then UK Fromresource from rESOURCE with variaBLE'))
     assert_not_none(self.ns.find_user_keyword(self.tcf, 'AND UK Fromresource from rESOURCE with variaBLE'))
     assert_none(self.ns.find_user_keyword(self.tcf, 'given and UK Fromresource from rESOURCE with variaBLE'))
Beispiel #29
0
 def test_find_default_keywords(self):
     all_kws = self.ns.get_all_keywords([])
     assert_not_none(all_kws)
     self.assert_in_keywords(all_kws, 'Should Be Equal')
Beispiel #30
0
 def test_find_user_keyword_name_normalized(self):
     assert_not_none(self.ns.find_user_keyword(self.tcf, 'UK Fromresource from rESOURCE with variaBLE'))
     assert_none(self.ns.find_user_keyword(self.tcf, 'Copy List'))
Beispiel #31
0
 def _start_new_suite(self):
     self.lib.start_suite()
     assert_none(self.lib._libinst)
     inst = self.lib.get_instance()
     assert_not_none(inst)
     return inst
Beispiel #32
0
	def select_can_node(self):
		_node_id = self.scan_for_present_can_nodes()
		self._active_node = self._network.add_node(_node_id, self._od_file)
		assert_not_none(self._active_node, 'No node has been selected')
		assert_true(self._od_file, "Can't find {} object dictionary file".format(self._od_file))
Beispiel #33
0
	def rpdo_read(self, number):
		assert_not_none(self._active_node, 'No node has been selected')
		if number < 1 or number > 4:
			logger.warn('PDO Map number out of range. Can not publish RPDO object.')
		else:
			self._active_node.rpdo[number].read()
Beispiel #34
0
 def test_start_suite_flushes_instance(self):
     assert_none(self.lib._libinst)
     inst = self.lib.get_instance()
     assert_not_none(inst)
     assert_false(inst is self.instance)
 def test_get_env_var(self):
     assert_not_none(get_env_var("PATH"))
     assert_equals(get_env_var(TEST_VAR), TEST_VAL)
     assert_none(get_env_var("NoNeXiStInG"))
     assert_equals(get_env_var("NoNeXiStInG", "default"), "default")
Beispiel #36
0
def should_be_not_none(src):
    _debug_response(src)
    assert_not_none(src)
 def test_assert_not_none(self):
     assert_not_none('Not None')
     assert_raises_with_msg(AE, "message: is None",
                            assert_not_none, None, 'message')
     assert_raises_with_msg(AE, "message",
                            assert_not_none, None, 'message', False)
Beispiel #38
0
 def test_find_default_keywords(self):
     all_kws = self.ns.get_all_keywords([])
     assert_not_none(all_kws)
     self.assert_in_keywords(all_kws, 'Should Be Equal')
Beispiel #39
0
 def test_find_user_keyword_name_normalized(self):
     assert_not_none(
         self.ns.find_user_keyword(
             self.tcf, 'UK Fromresource from rESOURCE with variaBLE'))
     assert_none(self.ns.find_user_keyword(self.tcf, 'Copy List'))
def should_be_not_none(src):

    assert_not_none(src)
Beispiel #41
0
 def test_get_env_var(self):
     assert_not_none(get_env_var('PATH'))
     assert_equal(get_env_var(TEST_VAR), TEST_VAL)
     assert_none(get_env_var('NoNeXiStInG'))
     assert_equal(get_env_var('NoNeXiStInG', 'default'), 'default')
Beispiel #42
0
 def test_assert_not_none(self):
     assert_not_none('Not None')
     assert_raises_with_msg(AE, "message: is None",
                            assert_not_none, None, 'message')
     assert_raises_with_msg(AE, "message",
                            assert_not_none, None, 'message', False)
Beispiel #43
0
	def pdo_readall(self):
		assert_not_none(self._active_node, 'No node has been selected')
		self._active_node.pdo.read()