Changeset: cfe72d1949b8 for MonetDB URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=cfe72d1949b8 Modified Files: sql/test/mapi/Tests/utf8test.SQL.py testing/process.py Branch: mtest Log Message:
Converted test utf8test. diffs (177 lines): diff --git a/sql/test/mapi/Tests/utf8test.SQL.py b/sql/test/mapi/Tests/utf8test.SQL.py --- a/sql/test/mapi/Tests/utf8test.SQL.py +++ b/sql/test/mapi/Tests/utf8test.SQL.py @@ -5,10 +5,10 @@ try: except ImportError: import process -def client(args, text=True): - with process.client('sql', args=args, - stdout=process.PIPE, stderr=process.PIPE, - text=text) as clt: +def client(args, encoding=None, format=None, text=True): + with process.client('sql', args=args, echo=False, + stdout=process.PIPE, stderr=process.PIPE, + text=text, encoding=encoding, format=format) as clt: return clt.communicate() def printit(file, string): @@ -18,60 +18,56 @@ def printit(file, string): file.write('\n') funny = u'\u00e0\u00e1\u00e2\u00e3\u00e4\u00e5' -if sys.version_info[0] == 2: - funny = funny.encode('utf-8') + +text1 = 'value without special characters' +text2 = 'funny characters: %s' % funny + +expectraw = f'''% sys.utf8test # table_name +% s # name +% varchar # type +% 32 # length +[ "{text1}"\t] +[ "{text2}"\t] +''' +expectsql = f'''+----------------------------------+ +| s | ++==================================+ +| {text1} | +| {text2} | ++----------------------------------+ +2 tuples +''' +expecterr = 'write error: stream stdout: invalid multibyte sequence\n' out, err = client(['-s', 'create table utf8test (s varchar(50))']) -printit(sys.stdout, out) -printit(sys.stderr, err) -out, err = client(['-s', "insert into utf8test values ('value without special characters')"]) -printit(sys.stdout, out) -printit(sys.stderr, err) -out, err = client(['-E%s' % locale.getpreferredencoding(), '-s', "insert into utf8test values ('funny characters: %s')" % funny]) -printit(sys.stdout, out) -printit(sys.stderr, err) -out, err = client(['-Eutf-8', '-fraw', '-s', 'select * from utf8test']) -printit(sys.stdout, out) -printit(sys.stderr, err) -out, err = client(['-Eutf-8', '-fsql', '-s', 'select * from utf8test']) -printit(sys.stdout, out) -printit(sys.stderr, err) -out, err = client(['-fraw', '-Eiso-8859-1', '-s', 'select * from utf8test'], - text=False) -out = out.decode('iso-8859-1') -err = err.decode('iso-8859-1') -if sys.version_info[0] == 2: - out = out.encode('utf-8') - err = err.encode('utf-8') -printit(sys.stdout, out) -printit(sys.stderr, err) -out, err = client(['-fsql', '-Eiso-8859-1', '-s', 'select * from utf8test'], - text=False) -out = out.decode('iso-8859-1') -err = err.decode('iso-8859-1') -if sys.version_info[0] == 2: - out = out.encode('utf-8') - err = err.encode('utf-8') -printit(sys.stdout, out) -printit(sys.stderr, err) -out, err = client(['-fraw', '-Eus-ascii', '-s', 'select * from utf8test'], - text=False) -out = out.decode('us-ascii') -err = err.decode('us-ascii') -if sys.version_info[0] == 2: - out = out.encode('utf-8') - err = err.encode('utf-8') -printit(sys.stdout, out) -printit(sys.stderr, err) -out, err = client(['-fsql', '-Eus-ascii', '-s', 'select * from utf8test'], - text=False) -out = out.decode('us-ascii') -err = err.decode('us-ascii') -if sys.version_info[0] == 2: - out = out.encode('utf-8') - err = err.encode('utf-8') -printit(sys.stdout, out) -printit(sys.stderr, err) +out, err = client(['-s', f"insert into utf8test values ('{text1}')"]) +out, err = client(['-s', f"insert into utf8test values ('{text2}')"], encoding=locale.getpreferredencoding()) +out, err = client(['-s', 'select * from utf8test'], encoding='utf-8', format='raw') +if out != expectraw: + sys.stdout.write('utf-8, raw:\n') + sys.stdout.write(out) +out, err = client(['-s', 'select * from utf8test'], encoding='utf-8', format='sql') +if out != expectsql: + sys.stdout.write('utf-8, sql:\n') + sys.stdout.write(out) +out, err = client(['-s', 'select * from utf8test'], + text=False, encoding='iso-8859-1', format='raw') +if out != expectraw: + sys.stdout.write('iso-8859-1, raw:\n') + sys.stdout.write(out) +out, err = client(['-s', 'select * from utf8test'], + text=False, encoding='iso-8859-1', format='sql') +if out != expectsql: + sys.stdout.write('iso-8859-1, sql:\n') + sys.stdout.write(out) +out, err = client(['-s', 'select * from utf8test'], + text=False, encoding='us-ascii', format='raw') +if err != expecterr: + sys.stdout.write('us-ascii, raw:\n') + sys.stdout.write(err) +out, err = client(['-s', 'select * from utf8test'], + text=False, encoding='us-ascii', format='sql') +if err != expecterr: + sys.stdout.write('us-ascii, sql:\n') + sys.stdout.write(err) out, err = client(['-s', 'drop table utf8test']) -printit(sys.stdout, out) -printit(sys.stderr, err) diff --git a/testing/process.py b/testing/process.py --- a/testing/process.py +++ b/testing/process.py @@ -232,7 +232,7 @@ class client(Popen): server=None, port=None, dbname=None, host=None, user='monetdb', passwd='monetdb', log=False, interactive=None, echo=None, format=None, - input=None, communicate=False, text=True): + input=None, communicate=False, text=True, encoding=None): '''Start a client process.''' if lang == 'mal': cmd = _mal_client[:] @@ -257,11 +257,23 @@ class client(Popen): elif '-e' not in cmd and echo: cmd.append('-e') if format is not None: - for c in cmd: - if c.startswith('-f'): - cmd.remove(c) + for i in range(len(cmd)): + if cmd[i] == '-f' or cmd[i] == '--format': + del cmd[i:i+2] + break + if cmd[i].startswith('-f') or cmd[i].startswith('--format='): + del cmd[i] break cmd.append('-f' + format) + if encoding is not None: + for i in range(len(cmd)): + if cmd[i] == '-E' or cmd[i] == '--encoding': + del cmd[i:i+2] + break + if cmd[i].startswith('-E') or cmd[i].startswith('--encoding='): + del cmd[i] + break + cmd.append('-E' + encoding) env = None @@ -333,7 +345,7 @@ class client(Popen): stderr=stderr, shell=False, env=env, - encoding='utf-8', + encoding=encoding or 'utf-8', text=text) if stdout == PIPE: self.stdout = _BufferedPipe(self.stdout) _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list