0

I am doing some unit testing in general in python. I get below mention AssertionError. I want to check the temperature range that if it is less than 30 and greater than 25 , then code should pass, but it gives me error. I can't figure out where I am making mistake.

test_csv_read_data_headers (__main__.ParseCSVTest) ... ok
test_data_fuelConsumption (__main__.ParseCSVTest) ... ok
test_data_temperature (__main__.ParseCSVTest) ...FAIL
test_data_timestamp (__main__.ParseCSVTest) ... ok

======================================================================

FAIL: test_data_temp (main.ParseCSVTest)

Traceback (most recent call last):
File "try.py", line 36, in test_data_temperature
30 > ali > 25, True
AssertionError: False != True

Ran 4 tests in 0.014s

FAILED (failures=1)

the code is as follow for temperature portion where my test fails.

def test_data_temperature(self):                
    column = [row[0].split()[3] for row in read_data(self.data)[1:]]                      
    ali = column[0:4]
    print ali                          
    self.assertEqual(
            30 > ali > 25, True 
            )

I print data in ali and it is in form of a list

['25.8', '25.6', '25.8', '25.8']  

I am confuse that how can I check range of this and make assertions so that it pass the test. If somebody give a tip or example. I will really grateful.

1
  • 4
    If it's a list, then indeed it is not true that it is between 30 and 25. Commented Nov 24, 2016 at 11:12

1 Answer 1

5

You are comparing a list to an integer.

You need to compare each value individually (eg using the python builtin all). Try something like

self.assertTrue(all(30 > a > 25 for a in ali))

You could also check the min and max value of the list. Slightly (negligibly) worse performance wise (I think?) but would give you more information if/when the test fails.

self.assertTrue(max(ali) < 30)
self.assertTrue(min(ali) > 25)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.