I have a list CountryList[] defined in my function and I want to check that it is not empty. I initialize it as empty but later on in the function data is put into it. This is the unit test I have typed.
def assertEmpty(self, CountryList):
self.assertFalse(CountryList)
def assertNotEmpty(self, CountryList):
self.assertTrue(CountryList)
This is the method in my program.
def onCountry(self, doc_id):
if(doc_id==None):
return
output_list = self.findBySubjectDocId(doc_id)
country_list=[]
for x in output_list:
country_id=x["visitor_country"]
if(SHOW_FULL_NAMES):
country_id=pc.country_alpha2_to_country_name(country_id)
country_list.append(country_id)
ts=pd.Series(country_list).value_counts().plot(kind='bar',color='purple')
plt.xticks(rotation='horizontal')
plt.xlabel('Country')
plt.ylabel('Number of Viewers')
plt.title("Viewers based on Country")
ts.plot()
plt.show()
print("Countries of Visitors:")
x = []
y = []
for k,v in Counter(country_list).items():
x.append(k)
y.append(v)
print(k,"-",v)
Do you suggest I test out this code some other way? or is the above testing acceptable?