Esempio n. 1
0
    def test_persist_read_error(self):
        # bad pattern
        content = """
        {
            "patterns": [
                "bad string"
            ]
        }
        """
        with self.assertRaises(PersistError):
            AutoQueuePersist.from_str(content)

        # empty json
        content = ""
        with self.assertRaises(PersistError):
            AutoQueuePersist.from_str(content)

        # missing keys
        content = "{}"
        with self.assertRaises(PersistError):
            AutoQueuePersist.from_str(content)

        # malformed
        content = "{"
        with self.assertRaises(PersistError):
            AutoQueuePersist.from_str(content)
Esempio n. 2
0
    def test_to_and_from_str(self):
        persist = AutoQueuePersist()
        persist.add_pattern(AutoQueuePattern(pattern="one"))
        persist.add_pattern(AutoQueuePattern(pattern="two"))
        persist.add_pattern(AutoQueuePattern(pattern="th ree"))
        persist.add_pattern(AutoQueuePattern(pattern="fo.ur"))
        persist.add_pattern(AutoQueuePattern(pattern="fi\"ve"))
        persist.add_pattern(AutoQueuePattern(pattern="si'x"))

        persist_actual = AutoQueuePersist.from_str(persist.to_str())
        self.assertEqual(persist.patterns, persist_actual.patterns)
Esempio n. 3
0
 def test_from_str(self):
     content = """
     {{
         "patterns": [
             "{}",
             "{}",
             "{}",
             "{}",
             "{}",
             "{}"
         ]
     }}
     """.format(
         AutoQueuePattern(pattern="one").to_str().replace("\\",
                                                          "\\\\").replace(
                                                              "\"", "\\\""),
         AutoQueuePattern(pattern="two").to_str().replace("\\",
                                                          "\\\\").replace(
                                                              "\"", "\\\""),
         AutoQueuePattern(pattern="th ree").to_str().replace(
             "\\", "\\\\").replace("\"", "\\\""),
         AutoQueuePattern(pattern="fo.ur").to_str().replace(
             "\\", "\\\\").replace("\"", "\\\""),
         AutoQueuePattern(pattern="fi\"ve").to_str().replace(
             "\\", "\\\\").replace("\"", "\\\""),
         AutoQueuePattern(pattern="si'x").to_str().replace(
             "\\", "\\\\").replace("\"", "\\\""))
     print(content)
     print(AutoQueuePattern(pattern="fi\"ve").to_str())
     persist = AutoQueuePersist.from_str(content)
     golden_patterns = {
         AutoQueuePattern(pattern="one"),
         AutoQueuePattern(pattern="two"),
         AutoQueuePattern(pattern="th ree"),
         AutoQueuePattern(pattern="fo.ur"),
         AutoQueuePattern(pattern="fi\"ve"),
         AutoQueuePattern(pattern="si'x")
     }
     self.assertEqual(golden_patterns, persist.patterns)