From 77aeaba6795b1d1a526dccc5f964911176bad2cc Mon Sep 17 00:00:00 2001 From: karim hamidou Date: Fri, 29 Nov 2013 10:22:22 +0100 Subject: [PATCH] fixed failing test --- src/back/kite/filterdaemon.py | 19 ++++++++----------- src/back/tests/test_filterdaemon.py | 5 ++--- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/back/kite/filterdaemon.py b/src/back/kite/filterdaemon.py index 7e037ab..def39d9 100644 --- a/src/back/kite/filterdaemon.py +++ b/src/back/kite/filterdaemon.py @@ -72,9 +72,7 @@ class DumperThread(threading.Thread): print "Dumping threads index" threads_index.save() -def process_new_email(path): - global threads_index - +def process_new_email(path, threads_index): with open(path, "r") as fd: parser = email.parser.HeaderParser() email_headers = parser.parse(fd) @@ -82,11 +80,11 @@ def process_new_email(path): if subject != None: subject = headers.cleanup_subject(subject) - if subject in threads_index.data: - threads_index.data[subject].append(path) + if subject in threads_index["data"]: + threads_index["data"][subject].append(path) else: # create a new thread - threads_index.data[subject] = [path] + threads_index["data"][subject] = [path] class ProcessorThread(threading.Thread): @@ -94,10 +92,9 @@ class ProcessorThread(threading.Thread): threading.Thread.__init__(self) self.path = path - global threads_index - threads_index = JsonFile(os.path.join(self.path, "threads_index.json")) - if threads_index.data == None: - threads_index.data = {} + self.threads_index = JsonFile(os.path.join(self.path, "threads_index.json")) + if self.threads_index.data == None: + self.threads_index.data = {} def run(self): while True: @@ -105,7 +102,7 @@ class ProcessorThread(threading.Thread): event = events_queue.pop(0) if event["type"] == "create": try: - self.process_new_email(event["path"]) + self.process_new_email(event["path"], self.threads_index) except IOError: # This may be a Postfix/Dovecot temporary file. Ignore it. pass diff --git a/src/back/tests/test_filterdaemon.py b/src/back/tests/test_filterdaemon.py index 9ecfb5d..1867cc6 100644 --- a/src/back/tests/test_filterdaemon.py +++ b/src/back/tests/test_filterdaemon.py @@ -1,10 +1,9 @@ import unittest import kite.filterdaemon as filterdaemon -threads_index = {"data": {}} class TestEmailProcessor(unittest.TestCase): def test_process_email(self): - global threads_index - filterdaemon.process_new_email("mocks/test_process_email.txt") + threads_index = {"data": {}} + filterdaemon.process_new_email("mocks/test_process_email.txt", threads_index) self.assertTrue("Hey, How are you ?" in threads_index["data"]) -- 2.43.0