Exemple #1
0
 def test_debug_with_erasure(self):
     d = {
         "id":
         "741fa660-3880-416e-a959-11111111111",
         "timestamp":
         1587723588670,
         "client":
         "dstack-py",
         "version":
         "0.3.0",
         "os": {
             "sysname": "Darwin",
             "release": "19.3.0",
             "version":
             "Darwin Kernel Version 19.3.0: Thu Jan  9 20:58:23 PST 2020;",
             "machine": "x86_64"
         },
         "message":
         "my message",
         "attachments": [{
             "data": "test data",
             "type": "image/svg",
             "description": "My first plot",
             "params": {
                 "x": 10,
                 "y": 20
             }
         }, {
             "data": "test data 2",
             "type": "image/svg",
             "description": "My second plot",
             "params": {
                 "x": 100,
                 "y": 200
             }
         }],
         "stack":
         "user/my_stack"
     }
     my_logger = log.InMemoryLogger()
     # test default level ERASE_BINARY_DATA | ERASE_PARAM_VALUES
     log.enable(logger=my_logger)
     log.debug(func=log.erase_sensitive_data, data=d, extra="extra")
     d1 = json.loads(my_logger.io.getvalue())
     data = d1["data"]
     for i in [0, 1]:
         self.assertTrue(
             data["attachments"][i]["data"].startswith("erased"))
         self.assertTrue(
             data["attachments"][i]["params"]["x"].startswith("erased"))
         self.assertTrue(
             data["attachments"][i]["params"]["y"].startswith("erased"))
     self.assertEqual("extra", d1["extra"])
Exemple #2
0
 def test_simple_log(self):
     my_logger = log.InMemoryLogger()
     log.enable(logger=my_logger)
     self.assertTrue(log.debug(data={"test": 123}, url="api/test"))
     self.assertTrue(log.debug(data="hello", x=10, y=20))
     lines = my_logger.io.getvalue().splitlines()
     self.assertEqual(2, len(lines))
     d = json.loads(lines[0])
     self.assertTrue("time" in d)
     self.assertEqual(123, d["data"]["test"])
     self.assertEqual("api/test", d["url"])
     d = json.loads(lines[1])
     self.assertTrue("time" in d)
     self.assertEqual(10, d["x"])
     self.assertEqual(20, d["y"])
     log.disable()
     self.assertFalse(log.debug(test="test"))
Exemple #3
0
 def test_none(self):
     my_logger = log.InMemoryLogger()
     log.enable(logger=my_logger)
     log.debug(data=None, extra=None)