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

Commit75f9d17

Browse files
committed
Make Python tests more portable
Newer Python versions randomize the hash seed for dictionaries,resulting in a random output order, which messes up the regression testdiffs.Instead, use Python assert to compare the dictionaries with theirexpected value.
1 parentac6f229 commit75f9d17

File tree

2 files changed

+8
-16
lines changed

2 files changed

+8
-16
lines changed

‎contrib/hstore_plpython/expected/hstore_plpython.out

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,10 @@ CREATE FUNCTION test1arr(val hstore[]) RETURNS int
4343
LANGUAGE plpythonu
4444
TRANSFORM FOR TYPE hstore
4545
AS $$
46-
plpy.info(repr(val))
46+
assert(val == [{'aa': 'bb', 'cc': None}, {'dd': 'ee'}])
4747
return len(val)
4848
$$;
4949
SELECT test1arr(array['aa=>bb, cc=>NULL'::hstore, 'dd=>ee']);
50-
INFO: [{'aa': 'bb', 'cc': None}, {'dd': 'ee'}]
51-
CONTEXT: PL/Python function "test1arr"
5250
test1arr
5351
----------
5452
2
@@ -88,18 +86,14 @@ LANGUAGE plpythonu
8886
TRANSFORM FOR TYPE hstore
8987
AS $$
9088
rv = plpy.execute("SELECT 'aa=>bb, cc=>NULL'::hstore AS col1")
91-
plpy.info(repr(rv[0]["col1"]))
89+
assert(rv[0]["col1"] == {'aa': 'bb', 'cc': None})
9290

9391
val = {'a': 1, 'b': 'boo', 'c': None}
9492
plan = plpy.prepare("SELECT $1::text AS col1", ["hstore"])
9593
rv = plpy.execute(plan, [val])
96-
plpy.info(repr(rv[0]["col1"]))
94+
assert(rv[0]["col1"] == '"a"=>"1", "b"=>"boo", "c"=>NULL')
9795
$$;
9896
SELECT test3();
99-
INFO: {'aa': 'bb', 'cc': None}
100-
CONTEXT: PL/Python function "test3"
101-
INFO: '"a"=>"1", "b"=>"boo", "c"=>NULL'
102-
CONTEXT: PL/Python function "test3"
10397
test3
10498
-------
10599

@@ -118,16 +112,14 @@ CREATE FUNCTION test4() RETURNS trigger
118112
LANGUAGE plpythonu
119113
TRANSFORM FOR TYPE hstore
120114
AS $$
121-
plpy.info("Trigger row: {'a':%r, 'b':%r}" % (TD["new"]["a"], TD["new"]["b"]))
115+
assert(TD["new"] == {'a':1, 'b':{'aa': 'bb', 'cc': None}})
122116
if TD["new"]["a"] == 1:
123117
TD["new"]["b"] = {'a': 1, 'b': 'boo', 'c': None}
124118

125119
return "MODIFY"
126120
$$;
127121
CREATE TRIGGER test4 BEFORE UPDATE ON test1 FOR EACH ROW EXECUTE PROCEDURE test4();
128122
UPDATE test1 SET a = a;
129-
INFO: Trigger row: {'a': 1, 'b': {'aa': 'bb', 'cc': None}}
130-
CONTEXT: PL/Python function "test4"
131123
SELECT * FROM test1;
132124
a | b
133125
---+---------------------------------

‎contrib/hstore_plpython/sql/hstore_plpython.sql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ CREATE FUNCTION test1arr(val hstore[]) RETURNS int
3737
LANGUAGE plpythonu
3838
TRANSFORM FOR TYPE hstore
3939
AS $$
40-
plpy.info(repr(val))
40+
assert(val== [{'aa':'bb','cc': None}, {'dd':'ee'}])
4141
return len(val)
4242
$$;
4343

@@ -74,12 +74,12 @@ LANGUAGE plpythonu
7474
TRANSFORM FOR TYPE hstore
7575
AS $$
7676
rv=plpy.execute("SELECT 'aa=>bb, cc=>NULL'::hstore AS col1")
77-
plpy.info(repr(rv[0]["col1"]))
77+
assert(rv[0]["col1"]== {'aa':'bb','cc': None})
7878

7979
val= {'a':1,'b':'boo','c': None}
8080
plan=plpy.prepare("SELECT $1::text AS col1", ["hstore"])
8181
rv=plpy.execute(plan, [val])
82-
plpy.info(repr(rv[0]["col1"]))
82+
assert(rv[0]["col1"]=='"a"=>"1", "b"=>"boo", "c"=>NULL')
8383
$$;
8484

8585
SELECT test3();
@@ -94,7 +94,7 @@ CREATE FUNCTION test4() RETURNS trigger
9494
LANGUAGE plpythonu
9595
TRANSFORM FOR TYPE hstore
9696
AS $$
97-
plpy.info("Trigger row: {'a':%r, 'b':%r}" % (TD["new"]["a"], TD["new"]["b"]))
97+
assert(TD["new"]== {'a':1,'b':{'aa':'bb','cc': None}})
9898
if TD["new"]["a"]==1:
9999
TD["new"]["b"]= {'a':1,'b':'boo','c': None}
100100

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp