Mercurial > p > roundup > code
comparison test/test_config.py @ 8433:de1dac9abcb6
feat: change comment in dictConfig json file to // from #
Emacs json mode at least will properly indent when using // as a
comment character and not #.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Tue, 26 Aug 2025 22:24:00 -0400 |
| parents | 3210729950b1 |
| children | 66284037142e |
comparison
equal
deleted
inserted
replaced
| 8432:7f7749d86da8 | 8433:de1dac9abcb6 |
|---|---|
| 1115 def testDictLoggerConfigViaJson(self): | 1115 def testDictLoggerConfigViaJson(self): |
| 1116 | 1116 |
| 1117 # good base test case | 1117 # good base test case |
| 1118 config1 = dedent(""" | 1118 config1 = dedent(""" |
| 1119 { | 1119 { |
| 1120 "version": 1, # only supported version | 1120 "version": 1, // only supported version |
| 1121 "disable_existing_loggers": false, # keep the wsgi loggers | 1121 "disable_existing_loggers": false, // keep the wsgi loggers |
| 1122 | 1122 |
| 1123 "formatters": { | 1123 "formatters": { |
| 1124 # standard Roundup formatter including context id. | 1124 // standard Roundup formatter including context id. |
| 1125 "standard": { | 1125 "standard": { |
| 1126 "format": "%(asctime)s %(levelname)s %(name)s:%(module)s %(msg)s" | 1126 "format": "%(asctime)s %(levelname)s %(name)s:%(module)s %(msg)s" |
| 1127 }, | 1127 }, |
| 1128 # used for waitress wsgi server to produce httpd style logs | 1128 // used for waitress wsgi server to produce httpd style logs |
| 1129 "http": { | 1129 "http": { |
| 1130 "format": "%(message)s" | 1130 "format": "%(message)s" |
| 1131 } | 1131 } |
| 1132 }, | 1132 }, |
| 1133 "handlers": { | 1133 "handlers": { |
| 1134 # create an access.log style http log file | 1134 // create an access.log style http log file |
| 1135 "access": { | 1135 "access": { |
| 1136 "level": "INFO", | 1136 "level": "INFO", |
| 1137 "formatter": "http", | 1137 "formatter": "http", |
| 1138 "class": "logging.FileHandler", | 1138 "class": "logging.FileHandler", |
| 1139 "filename": "_test_instance/access.log" | 1139 "filename": "_test_instance/access.log" |
| 1140 }, | 1140 }, |
| 1141 # logging for roundup.* loggers | 1141 // logging for roundup.* loggers |
| 1142 "roundup": { | 1142 "roundup": { |
| 1143 "level": "DEBUG", | 1143 "level": "DEBUG", |
| 1144 "formatter": "standard", | 1144 "formatter": "standard", |
| 1145 "class": "logging.FileHandler", | 1145 "class": "logging.FileHandler", |
| 1146 "filename": "_test_instance/roundup.log" | 1146 "filename": "_test_instance/roundup.log" |
| 1147 }, | 1147 }, |
| 1148 # print to stdout - fall through for other logging | 1148 // print to stdout - fall through for other logging |
| 1149 "default": { | 1149 "default": { |
| 1150 "level": "DEBUG", | 1150 "level": "DEBUG", |
| 1151 "formatter": "standard", | 1151 "formatter": "standard", |
| 1152 "class": "logging.StreamHandler", | 1152 "class": "logging.StreamHandler", |
| 1153 "stream": "ext://sys.stdout" | 1153 "stream": "ext://sys.stdout" |
| 1154 } | 1154 } |
| 1155 }, | 1155 }, |
| 1156 "loggers": { | 1156 "loggers": { |
| 1157 "": { | 1157 "": { |
| 1158 "handlers": [ | 1158 "handlers": [ |
| 1159 "default" # used by wsgi/usgi | 1159 "default" // used by wsgi/usgi |
| 1160 ], | 1160 ], |
| 1161 "level": "DEBUG", | 1161 "level": "DEBUG", |
| 1162 "propagate": false | 1162 "propagate": false |
| 1163 }, | 1163 }, |
| 1164 # used by roundup.* loggers | 1164 // used by roundup.* loggers |
| 1165 "roundup": { | 1165 "roundup": { |
| 1166 "handlers": [ | 1166 "handlers": [ |
| 1167 "roundup" | 1167 "roundup" |
| 1168 ], | 1168 ], |
| 1169 "level": "DEBUG", | 1169 "level": "DEBUG", |
| 1170 "propagate": false # note pytest testing with caplog requires | 1170 "propagate": false // note pytest testing with caplog requires |
| 1171 # this to be true | 1171 // this to be true |
| 1172 }, | 1172 }, |
| 1173 "roundup.hyperdb": { | 1173 "roundup.hyperdb": { |
| 1174 "handlers": [ | 1174 "handlers": [ |
| 1175 "roundup" | 1175 "roundup" |
| 1176 ], | 1176 ], |
| 1177 "level": "INFO", # can be a little noisy INFO for production | 1177 "level": "INFO", // can be a little noisy INFO for production |
| 1178 "propagate": false | 1178 "propagate": false |
| 1179 }, | 1179 }, |
| 1180 "roundup.wsgi": { # using the waitress framework | 1180 "roundup.wsgi": { // using the waitress framework |
| 1181 "handlers": [ | 1181 "handlers": [ |
| 1182 "roundup" | 1182 "roundup" |
| 1183 ], | 1183 ], |
| 1184 "level": "DEBUG", | 1184 "level": "DEBUG", |
| 1185 "propagate": false | 1185 "propagate": false |
| 1186 }, | 1186 }, |
| 1187 "roundup.wsgi.translogger": { # httpd style logging | 1187 "roundup.wsgi.translogger": { // httpd style logging |
| 1188 "handlers": [ | 1188 "handlers": [ |
| 1189 "access" | 1189 "access" |
| 1190 ], | 1190 ], |
| 1191 "level": "DEBUG", | 1191 "level": "DEBUG", |
| 1192 "propagate": false | 1192 "propagate": false |
| 1213 log_config_filename) | 1213 log_config_filename) |
| 1214 self.assertIn("version", config) | 1214 self.assertIn("version", config) |
| 1215 self.assertEqual(config['version'], 1) | 1215 self.assertEqual(config['version'], 1) |
| 1216 | 1216 |
| 1217 # broken inline comment misformatted | 1217 # broken inline comment misformatted |
| 1218 test_config = config1.replace(": 1, #", ": 1, #") | 1218 test_config = config1.replace(": 1, //", ": 1, //") |
| 1219 with open(log_config_filename, "w") as log_config_file: | 1219 with open(log_config_filename, "w") as log_config_file: |
| 1220 log_config_file.write(test_config) | 1220 log_config_file.write(test_config) |
| 1221 | 1221 |
| 1222 with self.assertRaises(configuration.LoggingConfigError) as cm: | 1222 with self.assertRaises(configuration.LoggingConfigError) as cm: |
| 1223 config = self.db.config.load_config_dict_from_json_file( | 1223 config = self.db.config.load_config_dict_from_json_file( |
| 1224 log_config_filename) | 1224 log_config_filename) |
| 1225 self.assertEqual( | 1225 self.assertEqual( |
| 1226 cm.exception.args[0], | 1226 cm.exception.args[0], |
| 1227 ('Error parsing json logging dict ' | 1227 ('Error parsing json logging dict ' |
| 1228 '(%s) near \n\n ' | 1228 '(%s) near \n\n ' |
| 1229 '"version": 1, # only supported version\n\nExpecting ' | 1229 '"version": 1, // only supported version\n\nExpecting ' |
| 1230 'property name enclosed in double quotes: line 3 column 18.\n' | 1230 'property name enclosed in double quotes: line 3 column 18.\n' |
| 1231 'Maybe bad inline comment, 3 spaces needed before #.' % | 1231 'Maybe bad inline comment, 3 spaces needed before //.' % |
| 1232 log_config_filename) | 1232 log_config_filename) |
| 1233 ) | 1233 ) |
| 1234 | 1234 |
| 1235 # broken trailing , on last dict element | 1235 # broken trailing , on last dict element |
| 1236 test_config = config1.replace(' "ext://sys.stdout"', | 1236 test_config = config1.replace(' "ext://sys.stdout"', |
| 1316 log_config_filename) | 1316 log_config_filename) |
| 1317 ) | 1317 ) |
| 1318 | 1318 |
| 1319 # broken invalid level MANGO | 1319 # broken invalid level MANGO |
| 1320 test_config = config1.replace( | 1320 test_config = config1.replace( |
| 1321 ': "INFO", # can', | 1321 ': "INFO", // can', |
| 1322 ': "MANGO", # can') | 1322 ': "MANGO", // can') |
| 1323 with open(log_config_filename, "w") as log_config_file: | 1323 with open(log_config_filename, "w") as log_config_file: |
| 1324 log_config_file.write(test_config) | 1324 log_config_file.write(test_config) |
| 1325 | 1325 |
| 1326 # file is made relative to tracker dir. | 1326 # file is made relative to tracker dir. |
| 1327 self.db.config["LOGGING_CONFIG"] = '_test_log_config.json' | 1327 self.db.config["LOGGING_CONFIG"] = '_test_log_config.json' |
