Merge pull request #23 from sunu/testing

Fixed a test involving writing nicks to csv file.
This commit is contained in:
shaunagm 2014-05-22 12:38:22 -04:00
commit bbde4ae19a
2 changed files with 16 additions and 10 deletions

View File

@ -1,5 +1,6 @@
# Yay tests! # Yay tests!
import csv
import unittest import unittest
import newbot import newbot
import time import time
@ -39,11 +40,16 @@ class TestBotClass(unittest.TestCase):
def test_add_nick_to_csv(self): def test_add_nick_to_csv(self):
bot = newbot.Bot('test_nicks.csv') bot = newbot.Bot('test_nicks.csv')
bot.add_known_nick('Roger__') bot.add_known_nick('Roger__')
self.assertEqual(bot.known_nicks, [['Alice'], ['Bob'], ['Roger']]) with open('test_nicks.csv', 'rb') as csv_file:
known_nicks = []
csv_file_data = csv.reader(csv_file, delimiter=',', quotechar='|')
for row in csv_file_data:
known_nicks.append(row)
self.assertEqual(known_nicks, [['Alice'], ['Bob'], ['Roger']])
def tearDown(self): def tearDown(self):
with open('test_nicks.csv', 'w') as csv_file: with open('test_nicks.csv', 'w') as csv_file:
csv_file.write('Alice\nBob') csv_file.write('Alice\nBob\n')
class TestNewComerClass(unittest.TestCase): class TestNewComerClass(unittest.TestCase):
@ -92,7 +98,7 @@ class TestProcessNewcomers(unittest.TestCase):
def tearDown(self): def tearDown(self):
with open('test_nicks.csv', 'w') as csv_file: with open('test_nicks.csv', 'w') as csv_file:
csv_file.write('Alice\nBob') csv_file.write('Alice\nBob\n')
# #
# Not sure how to test check_messages. # Not sure how to test check_messages.