Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit61b7516

Browse files
committed
fix support for utf-8
1 parent650a7df commit61b7516

File tree

2 files changed

+45
-22
lines changed

2 files changed

+45
-22
lines changed

‎testgres/testgres.py

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
importtempfile
3939
importthreading
4040
importtime
41+
importtraceback
4142

4243
importport_for
4344

@@ -349,7 +350,7 @@ def _prepare_dir(self, destroy):
349350
# Copy backup to new data dir
350351
shutil.copytree(data1,data2)
351352
exceptExceptionase:
352-
raiseBackupException(str(e))
353+
raiseBackupException(_explain_exception(e))
353354
else:
354355
base_dir=self.base_dir
355356

@@ -691,13 +692,13 @@ def print_node_file(node_file):
691692
return"### file not found ###\n"
692693

693694
error_text= (
694-
"Cannot start node\n"
695-
"{}\n"# pg_ctl log
696-
"{}:\n----\n{}\n"# postgresql.log
697-
"{}:\n----\n{}\n"# postgresql.conf
698-
"{}:\n----\n{}\n"# pg_hba.conf
699-
"{}:\n----\n{}\n"# recovery.conf
700-
).format(str(e),
695+
u"Cannot start node\n"
696+
u"{}\n"# pg_ctl log
697+
u"{}:\n----\n{}\n"# postgresql.log
698+
u"{}:\n----\n{}\n"# postgresql.conf
699+
u"{}:\n----\n{}\n"# pg_hba.conf
700+
u"{}:\n----\n{}\n"# recovery.conf
701+
).format(_explain_exception(e),
701702
log_filename,print_node_file(log_filename),
702703
conf_filename,print_node_file(conf_filename),
703704
hba_filename,print_node_file(hba_filename),
@@ -867,7 +868,9 @@ def safe_psql(self, dbname, query, username=None):
867868

868869
ret,out,err=self.psql(dbname,query,username=username)
869870
ifret:
870-
raiseQueryException(six.text_type(err))
871+
iferr:
872+
err=err.decode('utf-8')
873+
raiseQueryException(err)
871874
returnout
872875

873876
defdump(self,dbname,filename=None):
@@ -1041,7 +1044,7 @@ def catchup(self):
10411044
lsn=master.execute('postgres',poll_lsn)[0][0]
10421045
self.poll_query_until('postgres',wait_lsn.format(lsn))
10431046
exceptExceptionase:
1044-
raiseCatchUpException(str(e))
1047+
raiseCatchUpException(_explain_exception(e))
10451048

10461049
defpgbench_init(self,dbname='postgres',scale=1,options=[]):
10471050
"""
@@ -1103,6 +1106,15 @@ def connect(self, dbname='postgres', username=None):
11031106
username=username)
11041107

11051108

1109+
def_explain_exception(e):
1110+
"""
1111+
Use this function instead of str(e).
1112+
"""
1113+
1114+
lines=traceback.format_exception_only(type(e),e)
1115+
return''.join(lines)
1116+
1117+
11061118
def_cached_initdb(data_dir,initdb_logfile,initdb_params=[]):
11071119
"""
11081120
Perform initdb or use cached node files.
@@ -1113,7 +1125,7 @@ def call_initdb(_data_dir):
11131125
_params= [_data_dir,"-N"]+initdb_params
11141126
_execute_utility("initdb",_params,initdb_logfile)
11151127
exceptExceptionase:
1116-
raiseInitNodeException(str(e))
1128+
raiseInitNodeException(_explain_exception(e))
11171129

11181130
# Call initdb if we have custom params
11191131
ifinitdb_paramsornotTestgresConfig.cache_initdb:
@@ -1144,7 +1156,7 @@ def rm_cached_data_dir(rm_dir):
11441156
shutil.copytree(cached_data_dir,data_dir)
11451157

11461158
exceptExceptionase:
1147-
raiseInitNodeException(str(e))
1159+
raiseInitNodeException(_explain_exception(e))
11481160

11491161

11501162
def_execute_utility(util,args,logfile,write_to_pipe=True):
@@ -1174,23 +1186,29 @@ def _execute_utility(util, args, logfile, write_to_pipe=True):
11741186

11751187
# get result
11761188
out,_=process.communicate()
1177-
out=''ifnotoutelsesix.text_type(out)
11781189

11791190
# write new log entry if possible
11801191
try:
11811192
withopen(logfile,"a")asfile_out:
1182-
# write util name + args
1183-
file_out.write(''.join(map(lambdax:str(x)+' ',
1184-
[util]+args)))
1185-
file_out.write('\n')
1186-
file_out.write(out)
1193+
# write util name
1194+
file_out.write(util)
1195+
# write args
1196+
forarginargs:
1197+
file_out.write(arg)
1198+
withopen(logfile,"ab")asfile_out:
1199+
# write output
1200+
ifout:
1201+
file_out.write(out)
11871202
exceptIOError:
11881203
pass
11891204

1205+
# decode output
1206+
out=''ifnotoutelseout.decode('utf-8')
1207+
11901208
ifprocess.returncode:
11911209
error_text= (
1192-
"{} failed\n"
1193-
"log:\n----\n{}\n"
1210+
u"{} failed\n"
1211+
u"log:\n----\n{}\n"
11941212
).format(util,out)
11951213

11961214
raiseExecUtilException(error_text,process.returncode)

‎tests/test_simple.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env python
2+
# coding: utf-8
23

34
importos
45
importre
@@ -364,14 +365,18 @@ def test_logging(self):
364365
withget_new_node('master',use_logging=True)asmaster:
365366
master.init().start()
366367

368+
# execute a dummy query a few times
369+
foriinrange(20):
370+
master.execute('postgres','select 1')
371+
372+
# let logging worker do the job
367373
importtime
368374
time.sleep(0.5)
369375

370376
# check that master's port is found
371377
withopen(logfile.name,'r')aslog:
372378
lines=log.readlines()
373-
port=str(master.port)
374-
self.assertTrue(any(portinsforsinlines))
379+
self.assertTrue(any('select'insforsinlines))
375380

376381
deftest_pgbench(self):
377382
withget_new_node('node')asnode:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp