Commits

Boris FELD committed b237fe8

Add a test for number_of_values method in Messenger.

Comments (0)

Files changed (2)

pytasks/Messenger.py

                 return len(self.__values[key])
 
             else:
-
                 matched = 0
-
                 for value in self.__values[key]:
                     if value.has_tags(tags):
                         matched += 1
-
                 return matched
 
         else:
-            return -1
+            return 0
 
     def get_keys(self):
         return self.__values.keys()

tests/TestMessenger.py

 sys.path.insert(0, os.path.realpath('../'))
 
 from pytasks.Messenger import (Messenger, _split_sub_type)
+from pytasks.Output import Output
 import unittest
 
 class MessengerStoreTestCase(unittest.TestCase):
         self.assertEquals(list(_split_sub_type(subtype2)),
                           ['file', 'file.archive', 'file.archive.sdist',
                            'file.archive.sdist.python'])
+
+    def testNumberOfValues(self):
+
+        value = "value"
+
+        not_a_key = "non"
+        one_value = "one"
+        mutliple_value = "multiple"
+
+        tag1 = "tag1"
+        tag2 = "tag2"
+
+        output_tag1 = Output(value)
+        output_tag1.add_tag(tag1)
+
+        output_tags = Output(value)
+        output_tags.add_tag(tag1)
+        output_tags.add_tag(tag2)
+
+        #Add some sample values
+        self.messenger.store(one_value, Output(value))
+        self.messenger.store(mutliple_value, Output(value))
+        self.messenger.store(mutliple_value, output_tag1)
+        self.messenger.store(mutliple_value, output_tags)
+
+        self.assertEquals(self.messenger.number_of_values(not_a_key), 0)
+        self.assertEquals(self.messenger.number_of_values(one_value), 1)
+        self.assertEquals(self.messenger.number_of_values(mutliple_value), 3)
+        self.assertEquals(self.messenger.number_of_values(mutliple_value, [tag1]), 2)
+        self.assertEquals(self.messenger.number_of_values(mutliple_value, [tag1, tag2]), 1)
+
 if __name__ == '__main':
     unittest.main()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.