Commit 75f9d176 authored by Peter Eisentraut's avatar Peter Eisentraut

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 test
diffs.

Instead, use Python assert to compare the dictionaries with their
expected value.
parent ac6f2295
...@@ -43,12 +43,10 @@ CREATE FUNCTION test1arr(val hstore[]) RETURNS int ...@@ -43,12 +43,10 @@ CREATE FUNCTION test1arr(val hstore[]) RETURNS int
LANGUAGE plpythonu LANGUAGE plpythonu
TRANSFORM FOR TYPE hstore TRANSFORM FOR TYPE hstore
AS $$ AS $$
plpy.info(repr(val)) assert(val == [{'aa': 'bb', 'cc': None}, {'dd': 'ee'}])
return len(val) return len(val)
$$; $$;
SELECT test1arr(array['aa=>bb, cc=>NULL'::hstore, 'dd=>ee']); SELECT test1arr(array['aa=>bb, cc=>NULL'::hstore, 'dd=>ee']);
INFO: [{'aa': 'bb', 'cc': None}, {'dd': 'ee'}]
CONTEXT: PL/Python function "test1arr"
test1arr test1arr
---------- ----------
2 2
...@@ -88,18 +86,14 @@ LANGUAGE plpythonu ...@@ -88,18 +86,14 @@ LANGUAGE plpythonu
TRANSFORM FOR TYPE hstore TRANSFORM FOR TYPE hstore
AS $$ AS $$
rv = plpy.execute("SELECT 'aa=>bb, cc=>NULL'::hstore AS col1") rv = plpy.execute("SELECT 'aa=>bb, cc=>NULL'::hstore AS col1")
plpy.info(repr(rv[0]["col1"])) assert(rv[0]["col1"] == {'aa': 'bb', 'cc': None})
val = {'a': 1, 'b': 'boo', 'c': None} val = {'a': 1, 'b': 'boo', 'c': None}
plan = plpy.prepare("SELECT $1::text AS col1", ["hstore"]) plan = plpy.prepare("SELECT $1::text AS col1", ["hstore"])
rv = plpy.execute(plan, [val]) rv = plpy.execute(plan, [val])
plpy.info(repr(rv[0]["col1"])) assert(rv[0]["col1"] == '"a"=>"1", "b"=>"boo", "c"=>NULL')
$$; $$;
SELECT test3(); SELECT test3();
INFO: {'aa': 'bb', 'cc': None}
CONTEXT: PL/Python function "test3"
INFO: '"a"=>"1", "b"=>"boo", "c"=>NULL'
CONTEXT: PL/Python function "test3"
test3 test3
------- -------
...@@ -118,7 +112,7 @@ CREATE FUNCTION test4() RETURNS trigger ...@@ -118,7 +112,7 @@ CREATE FUNCTION test4() RETURNS trigger
LANGUAGE plpythonu LANGUAGE plpythonu
TRANSFORM FOR TYPE hstore TRANSFORM FOR TYPE hstore
AS $$ AS $$
plpy.info("Trigger row: {'a': %r, 'b': %r}" % (TD["new"]["a"], TD["new"]["b"])) assert(TD["new"] == {'a': 1, 'b': {'aa': 'bb', 'cc': None}})
if TD["new"]["a"] == 1: if TD["new"]["a"] == 1:
TD["new"]["b"] = {'a': 1, 'b': 'boo', 'c': None} TD["new"]["b"] = {'a': 1, 'b': 'boo', 'c': None}
...@@ -126,8 +120,6 @@ return "MODIFY" ...@@ -126,8 +120,6 @@ return "MODIFY"
$$; $$;
CREATE TRIGGER test4 BEFORE UPDATE ON test1 FOR EACH ROW EXECUTE PROCEDURE test4(); CREATE TRIGGER test4 BEFORE UPDATE ON test1 FOR EACH ROW EXECUTE PROCEDURE test4();
UPDATE test1 SET a = a; UPDATE test1 SET a = a;
INFO: Trigger row: {'a': 1, 'b': {'aa': 'bb', 'cc': None}}
CONTEXT: PL/Python function "test4"
SELECT * FROM test1; SELECT * FROM test1;
a | b a | b
---+--------------------------------- ---+---------------------------------
......
...@@ -37,7 +37,7 @@ CREATE FUNCTION test1arr(val hstore[]) RETURNS int ...@@ -37,7 +37,7 @@ CREATE FUNCTION test1arr(val hstore[]) RETURNS int
LANGUAGE plpythonu LANGUAGE plpythonu
TRANSFORM FOR TYPE hstore TRANSFORM FOR TYPE hstore
AS $$ AS $$
plpy.info(repr(val)) assert(val == [{'aa': 'bb', 'cc': None}, {'dd': 'ee'}])
return len(val) return len(val)
$$; $$;
...@@ -74,12 +74,12 @@ LANGUAGE plpythonu ...@@ -74,12 +74,12 @@ LANGUAGE plpythonu
TRANSFORM FOR TYPE hstore TRANSFORM FOR TYPE hstore
AS $$ AS $$
rv = plpy.execute("SELECT 'aa=>bb, cc=>NULL'::hstore AS col1") rv = plpy.execute("SELECT 'aa=>bb, cc=>NULL'::hstore AS col1")
plpy.info(repr(rv[0]["col1"])) assert(rv[0]["col1"] == {'aa': 'bb', 'cc': None})
val = {'a': 1, 'b': 'boo', 'c': None} val = {'a': 1, 'b': 'boo', 'c': None}
plan = plpy.prepare("SELECT $1::text AS col1", ["hstore"]) plan = plpy.prepare("SELECT $1::text AS col1", ["hstore"])
rv = plpy.execute(plan, [val]) rv = plpy.execute(plan, [val])
plpy.info(repr(rv[0]["col1"])) assert(rv[0]["col1"] == '"a"=>"1", "b"=>"boo", "c"=>NULL')
$$; $$;
SELECT test3(); SELECT test3();
...@@ -94,7 +94,7 @@ CREATE FUNCTION test4() RETURNS trigger ...@@ -94,7 +94,7 @@ CREATE FUNCTION test4() RETURNS trigger
LANGUAGE plpythonu LANGUAGE plpythonu
TRANSFORM FOR TYPE hstore TRANSFORM FOR TYPE hstore
AS $$ AS $$
plpy.info("Trigger row: {'a': %r, 'b': %r}" % (TD["new"]["a"], TD["new"]["b"])) assert(TD["new"] == {'a': 1, 'b': {'aa': 'bb', 'cc': None}})
if TD["new"]["a"] == 1: if TD["new"]["a"] == 1:
TD["new"]["b"] = {'a': 1, 'b': 'boo', 'c': None} TD["new"]["b"] = {'a': 1, 'b': 'boo', 'c': None}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment