Beispiel #1
0
 def test_replace_placeholders(self):
     """Replace $ placeholders in objects"""
     data = load_json.load_directory(DIRECTORY_PATH)
     data = load_json.replace_placeholders(data)
     data = data["strings"]
     self.assertEqual(data["main"]["absolute"]["two_and_four"], "2 and 4")
     self.assertEqual(data["main"]["absolute"]["two_two"], "2 2")
     self.assertEqual(data["main"]["absolute"]["sub"], "sub")
     self.assertEqual(data["main"]["relative"]["two"], "2")
     self.assertEqual(data["main"]["relative"]["sub_and_not_absolute"], "sub and in_absolute")
     self.assertEqual(data["main"]["relative"]["same_level"], "same_level")
     self.assertEqual(data["from_others"]["absolute_hot_food"], "chicken")
     self.assertEqual(data["from_others"]["relative_cold"], "drink")
Beispiel #2
0
 def test_load_directory(self):
     """Load a directory with json files and convert it to python dictionnary"""
     data = load_json.load_directory(DIRECTORY_PATH)
     self.assertEqual(data["others"]["hot"]["food"], "chicken")
     self.assertEqual(data["others"]["cold"], "drink")
     data = data["strings"]
     self.assertEqual(data["sub"], "sub")
     self.assertEqual(data["main"]["two"], "2")
     self.assertEqual(data["main"]["absolute"]["not_absolute"], "in_absolute")
     self.assertEqual(data["main"]["absolute"]["two_and_four"], "$strings/main/two and 4")
     self.assertEqual(data["main"]["absolute"]["two_two"], "$strings/main/two $strings/main/two")
     self.assertEqual(data["main"]["absolute"]["sub"], "$strings/sub")
     self.assertEqual(data["main"]["relative"]["two"], "$../two")
     self.assertEqual(
         data["main"]["relative"]["sub_and_not_absolute"], "$../../sub and $./.././absolute/not_absolute",
     )
     self.assertEqual(data["main"]["relative"]["same_level"], "$not_relative")
     self.assertEqual(data["from_others"]["absolute_hot_food"], "$others/hot/food")
     self.assertEqual(data["from_others"]["relative_cold"], "$../../others/cold")
Beispiel #3
0
 def init_ressources(self):
     """Initializes all ressources"""
     self.strings = load_json.load_directory("bot/replies")
     self.strings = load_json.replace_placeholders(self.strings)
 def strings(self):
     if not self._strings:
         self._strings = load_json.load_directory("bot/replies")
         self._strings = load_json.replace_placeholders(self.strings)
     return self._strings