2014-10-07 57 views
0

以下代碼發送命令生成密鑰然後檢查以確保沒有任何密碼相同。接近我的代碼結尾(我將在後面陳述)我不確定爲什麼我的先前分組現在聲明該對象沒有屬性組。我把它分組的權利,所以是任何想法...這是我到目前爲止的代碼:如何讓我的內容分組顯示在python

def PairingSecret(self): 
    # Enter submenu-------------------------------------------------------------------------- 
    ser = self.portMan 
    result = Test.TestResult.NOTRUN 
    if not ser.EnterSubmenu('siteprot'): 
     return Test.TestResult.NORESPONSE 

    # Send secret Cmd 
    ser.SendCmd("modal 0") 
    log = ser.SendCmd("secret") 

    # Verifying active and secret == 0 
    if ser.DoesContain(log, "active = 0" and "secret: 0") == False: 
     self.log.WriteError("Incorrect value for ACTIVE and SECRET key") 
     result = Test.TestResult.FAIL 

    else: 
     result = Test.TestResult.PASS 

    #Send Cmd 
    ser.SendCmd("modal 1") 
    log = ser.SendCmd("secret") 

    # verifying active == 1 and secret is a four digit 
    sec_value = re.search('(\d{4,4})$', log [1]) 

    if ser.DoesContain(log, "active = 1") == False: 
      self.log.WriteError("Incorrect value for Active key") 
      result = Test.TestResult.FAIL 

    else: 
     result = Test.TestResult.PASS 

    # Send Cmd then check secret 
    ser.SendCmd("modal 0") 
    ser.SendCmd("modal 1") 
    log = ser.SendCmd("secret") 

    # verifying active == 1 and secret is a four digit value != first secret 
    sec_value2 = re.search('(\d{1,4})$',log [1]) 

    if sec_value2: 
     secret = int(sec_value.group(1)) 
     secret2 = int(sec_value2.group(1)) 

     if secret == secret2: 
      result = Test.TestResult.FAIL 

    else: 
     result = Test.TestResult.PASS 

    # Send mod 0 command 
    ser.SendCmd("modal 0") 
    log = ser.SendCmd("secret") 

    if ser.DoesContain(log,"active = 0" and "secret: 0") == False: 
     self.log.WriteError("Incorrect value for ACTIVE and SECRET key\r\n") 
     result = Test.TestResult.FAIL 

    else: 
     result = Test.TestResult.PASS 

    # Send gensec and extract four digit value 
    log = ser.SendCmd("gensec") 
    gen_secret = re.search('(\d{4,4})$', log [1]) 

--------------------這是我的地方分組以實現祕密,SECRET2沒有顯示出ATTRIBUTES ----------

# Verify gen_secret != with first two modal 1 command secret 
    if gen_secret: 
     gen_sec = int(gen_secret.group(1)) 
     secret = int(sec_value.group(1)) 
     secret2 = int(sec_value2.group(1)) 

     if gen_sec == secret or secret2: 
      result = Test.TestResult.FAIL 

    else: 
     result = Test.TestResult.PASS 

    # Exit Submenu 
    if not ser.ExitSubmenu(): 
     return Test.TestResult.NORESPONSE 

    return result 

回答

1

此行可能是錯誤的:

if gen_sec == secret or secret2: 

,應該是:

if gen_sec == secret or gen_sec == secret2: 

if gen_sec in [secret, secret2]: 
相關問題