本文整理汇总了Python中pyrseas.testutils.fix_indent函数的典型用法代码示例。如果您正苦于以下问题:Python fix_indent函数的具体用法?Python fix_indent怎么用?Python fix_indent使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了fix_indent函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_create_aggregate_init_final
def test_create_aggregate_init_final(self):
"Create an aggregate with an INITCOND and a FINALFUNC"
self.db.execute("DROP AGGREGATE IF EXISTS a1(integer)")
self.db.execute_commit("DROP FUNCTION IF EXISTS f2(integer)")
self.db.execute_commit(DROP_STMT2)
inmap = self.std_map()
inmap['schema public'].update({'function f1(integer, integer)': {
'language': 'sql', 'returns': 'integer',
'source': SOURCE2,
'volatility': 'immutable'}})
inmap['schema public'].update({'function f2(integer)': {
'language': 'sql', 'returns': 'double precision',
'source': "SELECT $1::float",
'volatility': 'immutable'}})
inmap['schema public'].update({'aggregate a1(integer)': {
'sfunc': 'f1', 'stype': 'integer', 'initcond': '-1',
'finalfunc': 'f2(integer)'}})
dbsql = self.db.process_map(inmap)
self.assertEqual(fix_indent(dbsql[1]), CREATE_STMT2)
self.assertEqual(fix_indent(dbsql[2]),
"CREATE FUNCTION f2(integer) "
"RETURNS double precision LANGUAGE sql IMMUTABLE "
"AS $_$SELECT $1::float$_$")
self.assertEqual(fix_indent(dbsql[3]),
"CREATE AGGREGATE a1(integer) "
"(SFUNC = f1, STYPE = integer, FINALFUNC = f2, "
"INITCOND = '-1')")
开发者ID:rdunklau,项目名称:Pyrseas,代码行数:27,代码来源:test_function.py
示例2: test_create_table_with_defaults
def test_create_table_with_defaults(self):
"Create a table with two column DEFAULTs, one referring to a SEQUENCE"
self.db.execute_commit("DROP SEQUENCE IF EXISTS t1_c1_seq")
inmap = self.std_map()
inmap['schema public'].update({'table t1': {
'columns': [{'c1': {
'type': 'integer',
'not_null': True,
'default': "nextval('t1_c1_seq'::regclass)"}},
{'c2': {'type': 'text', 'not_null': True}},
{'c3': {
'type': 'date', 'not_null': True,
'default': "('now'::text)::date"}}]},
'sequence t1_c1_seq': {
'cache_value': 1, 'increment_by': 1, 'max_value': None,
'min_value': None, 'start_value': 1}})
dbsql = self.db.process_map(inmap)
self.assertEqual(fix_indent(dbsql[0]),
"CREATE TABLE t1 (c1 integer NOT NULL, "
"c2 text NOT NULL, "
"c3 date NOT NULL DEFAULT ('now'::text)::date)")
self.assertEqual(fix_indent(dbsql[1]),
"CREATE SEQUENCE t1_c1_seq START WITH 1 "
"INCREMENT BY 1 NO MAXVALUE NO MINVALUE CACHE 1")
self.assertEqual(dbsql[2], "ALTER TABLE t1 ALTER COLUMN c1 "
"SET DEFAULT nextval('t1_c1_seq'::regclass)")
开发者ID:rdunklau,项目名称:Pyrseas,代码行数:26,代码来源:test_table.py
示例3: test_create_with_foreign_key
def test_create_with_foreign_key(self):
"Create a table with a foreign key constraint"
inmap = self.std_map()
inmap['schema public'].update({'table t1': {
'columns': [{'c11': {'type': 'integer'}},
{'c12': {'type': 'text'}}]},
'table t2': {
'columns': [{'c21': {'type': 'integer'}},
{'c22': {'type': 'text'}},
{'c23': {'type': 'integer'}}],
'foreign_keys': {'t2_c23_fkey': {
'columns': ['c23'],
'references': {'columns': ['c11'],
'table': 't1'}}}}})
sql = self.to_sql(inmap)
# can't control which table will be created first
crt1 = 0
crt2 = 1
if 't1' in sql[1]:
crt1 = 1
crt2 = 0
self.assertEqual(fix_indent(sql[crt1]),
"CREATE TABLE t1 (c11 integer, c12 text)")
self.assertEqual(fix_indent(sql[crt2]),
"CREATE TABLE t2 (c21 integer, c22 text, "
"c23 integer)")
self.assertEqual(fix_indent(sql[2]),
"ALTER TABLE t2 ADD CONSTRAINT t2_c23_fkey "
"FOREIGN KEY (c23) REFERENCES t1 (c11)")
开发者ID:andreypopp,项目名称:Pyrseas,代码行数:29,代码来源:test_constraint.py
示例4: test_alter_foreign_key2
def test_alter_foreign_key2(self):
"Change foreign key: foreign column"
stmts = ["CREATE TABLE t1 (c11 INTEGER NOT NULL UNIQUE, "
"c12 INTEGER NOT NULL UNIQUE)",
"CREATE TABLE t2 (c21 INTEGER PRIMARY KEY NOT NULL, "
"c22 INTEGER, c23 INTEGER)",
"ALTER TABLE t2 ADD CONSTRAINT t2_c22_fkey " \
"FOREIGN KEY (c22) REFERENCES t1 (c11)"]
inmap = self.std_map()
inmap['schema public'].update({
'table t1': {'columns': [
{'c11': {'type': 'integer', 'not_null': True}},
{'c12': {'type': 'integer', 'not_null': True}}],
'unique_constraints': {
't1_c11_key': {'columns': ['c11']},
't1_c12_key': {'columns': ['c12']}}},
'table t2': {'columns': [
{'c21': {'type': 'integer', 'not_null': True}},
{'c22': {'type': 'integer'}},
{'c23': {'type': 'integer'}}],
'primary_key': {'t2_pkey': {'columns': ['c21']}},
'foreign_keys': {'t2_c22_fkey': {
'columns': ['c22'],
'references': {'columns': ['c12'],
'table': 't1'}}}}})
sql = self.to_sql(inmap, stmts)
self.assertEqual(2, len(sql))
self.assertEqual(fix_indent(sql[0]),
'ALTER TABLE t2 DROP CONSTRAINT t2_c22_fkey')
self.assertEqual(fix_indent(sql[1]),
'ALTER TABLE t2 ADD CONSTRAINT t2_c22_fkey ' \
'FOREIGN KEY (c22) REFERENCES t1 (c12)')
开发者ID:goldie80,项目名称:Pyrseas,代码行数:32,代码来源:test_constraint.py
示例5: test_create_wrapper_server
def test_create_wrapper_server(self):
"Create a foreign data wrapper and its server"
inmap = self.std_map()
inmap.update({'foreign data wrapper fdw1': {'server fs1': {}}})
sql = self.to_sql(inmap)
assert fix_indent(sql[0]) == CREATE_FDW_STMT
assert fix_indent(sql[1]) == CREATE_FS_STMT
开发者ID:conor1984,项目名称:Pyrseas,代码行数:7,代码来源:test_foreign.py
示例6: test_create_rule_nothing
def test_create_rule_nothing(self):
"Create a rule"
inmap = self.std_map()
inmap['schema sd'].update({'table t1': {
'columns': [{'c1': {'type': 'integer'}}, {'c2': {'type': 'text'}}],
'rules': {'r1': {'event': 'insert', 'actions': 'NOTHING'}}}})
sql = self.to_sql(inmap)
assert fix_indent(sql[0]) == CREATE_TABLE_STMT
assert fix_indent(sql[1]) == CREATE_STMT % ('INSERT', 'NOTHING')
开发者ID:perseas,项目名称:Pyrseas,代码行数:9,代码来源:test_rule.py
示例7: test_alter_statistics
def test_alter_statistics(self):
"Alter a table to add column statistics"
inmap = self.std_map()
inmap["schema public"].update(
{"table t1": {"columns": [{"c1": {"type": "integer", "statistics": 100}}, {"c2": {"type": "text"}}]}}
)
sql = self.to_sql(inmap, [CREATE_STMT1, "ALTER TABLE t1 ALTER c2 " "SET STATISTICS 1000"])
assert fix_indent(sql[0]) == "ALTER TABLE t1 ALTER COLUMN c1 SET STATISTICS 100"
assert fix_indent(sql[1]) == "ALTER TABLE t1 ALTER COLUMN c2 SET STATISTICS -1"
开发者ID:rhunwicks,项目名称:Pyrseas,代码行数:9,代码来源:test_column.py
示例8: test_change_column_types
def test_change_column_types(self):
"Change the datatypes of two columns"
inmap = self.std_map()
inmap["schema public"].update(
{"table t1": {"columns": [{"c1": {"type": "bigint"}}, {"c2": {"type": "varchar(25)"}}]}}
)
sql = self.to_sql(inmap, [CREATE_STMT1])
assert fix_indent(sql[0]) == "ALTER TABLE t1 ALTER COLUMN c1 TYPE bigint"
assert fix_indent(sql[1]) == "ALTER TABLE t1 ALTER COLUMN c2 TYPE varchar(25)"
开发者ID:rhunwicks,项目名称:Pyrseas,代码行数:9,代码来源:test_column.py
示例9: test_create_wrapper_server_mapping
def test_create_wrapper_server_mapping(self):
"Create a FDW, server and user mapping"
inmap = self.std_map()
inmap.update({'foreign data wrapper fdw1': {'server fs1': {
'user mappings': {'PUBLIC': {}}}}})
sql = self.to_sql(inmap)
assert fix_indent(sql[0]) == CREATE_FDW_STMT
assert fix_indent(sql[1]) == CREATE_FS_STMT
assert fix_indent(sql[2]) == CREATE_UM_STMT
开发者ID:conor1984,项目名称:Pyrseas,代码行数:9,代码来源:test_foreign.py
示例10: test_add_column4
def test_add_column4(self):
"Add two columns to a table that has a dropped column"
stmts = [CREATE_STMT2, DROP_COL_STMT]
inmap = self.std_map()
inmap['schema public'].update({'table t1': {
'columns': [{'c1': {'type': 'integer'}}, {'c2': {'type': 'text'}},
{'c3': {'type': 'date'}}, {'c4': {'type': 'text'}}]}})
sql = self.to_sql(inmap, stmts)
assert fix_indent(sql[0]) == "ALTER TABLE t1 ADD COLUMN c3 date"
assert fix_indent(sql[1]) == "ALTER TABLE t1 ADD COLUMN c4 text"
开发者ID:conor1984,项目名称:Pyrseas,代码行数:10,代码来源:test_column.py
示例11: test_create_with_primary_key
def test_create_with_primary_key(self):
"Create new table with single column primary key"
inmap = self.std_map()
inmap['schema public'].update({'table t1': {
'columns': [{'c1': {'type': 'text'}}, {'c2': {'type': 'integer'}}],
'primary_key': {'t1_pkey': {'columns': ['c2']}}}})
sql = self.to_sql(inmap)
assert fix_indent(sql[0]) == "CREATE TABLE t1 (c1 text, c2 integer)"
assert fix_indent(sql[1]) == "ALTER TABLE t1 ADD CONSTRAINT t1_pkey " \
"PRIMARY KEY (c2)"
开发者ID:court-jus,项目名称:Pyrseas,代码行数:10,代码来源:test_constraint.py
示例12: test_create_w_unique_constraint
def test_create_w_unique_constraint(self):
"Create new table with a single column unique constraint"
inmap = self.std_map()
inmap['schema public'].update({'table t1': {
'columns': [{'c1': {'type': 'integer'}}, {'c2': {'type': 'text'}}],
'unique_constraints': {'t1_c1_key': {'columns': ['c1']}}}})
sql = self.to_sql(inmap)
assert fix_indent(sql[0]) == "CREATE TABLE t1 (c1 integer, c2 text)"
assert fix_indent(sql[1]) == \
"ALTER TABLE t1 ADD CONSTRAINT t1_c1_key UNIQUE (c1)"
开发者ID:court-jus,项目名称:Pyrseas,代码行数:10,代码来源:test_constraint.py
示例13: test_create_domain_check
def test_create_domain_check(self):
"Create a domain with a CHECK constraint"
inmap = self.std_map()
inmap['schema sd'].update({'domain d1': {
'type': 'integer', 'check_constraints': {'d1_check': {
'expression': '(VALUE >= 1888)'}}}})
sql = self.to_sql(inmap)
assert fix_indent(sql[0]) == CREATE_STMT
assert fix_indent(sql[1]) == "ALTER DOMAIN sd.d1 ADD CONSTRAINT " + \
"d1_check CHECK (VALUE >= 1888)"
开发者ID:perseas,项目名称:Pyrseas,代码行数:10,代码来源:test_domain.py
示例14: test_drop_add_column3
def test_drop_add_column3(self):
"Drop and re-add table columns from table with dropped column"
stmts = [CREATE_STMT2, DROP_COL_STMT]
inmap = self.std_map()
inmap["schema public"].update(
{"table t1": {"columns": [{"c2": {"type": "text"}}, {"c3": {"type": "date"}}, {"c4": {"type": "text"}}]}}
)
sql = self.to_sql(inmap, stmts)
assert fix_indent(sql[0]) == "ALTER TABLE t1 ADD COLUMN c3 date"
assert fix_indent(sql[1]) == "ALTER TABLE t1 ADD COLUMN c4 text"
assert sql[2] == "ALTER TABLE t1 DROP COLUMN c1"
开发者ID:rhunwicks,项目名称:Pyrseas,代码行数:11,代码来源:test_column.py
示例15: test_change_column_types
def test_change_column_types(self):
"Change the datatypes of two columns"
inmap = self.std_map()
inmap['schema public'].update({'table t1': {
'columns': [{'c1': {'type': 'bigint'}},
{'c2': {'type': 'varchar(25)'}}]}})
sql = self.to_sql(inmap, [CREATE_STMT1])
assert fix_indent(sql[0]) == \
"ALTER TABLE t1 ALTER COLUMN c1 TYPE bigint"
assert fix_indent(sql[1]) == \
"ALTER TABLE t1 ALTER COLUMN c2 TYPE varchar(25)"
开发者ID:conor1984,项目名称:Pyrseas,代码行数:11,代码来源:test_column.py
示例16: test_drop_add_column3
def test_drop_add_column3(self):
"Drop and re-add table columns from table with dropped column"
stmts = [CREATE_STMT2, DROP_COL_STMT]
inmap = self.std_map()
inmap['schema public'].update({'table t1': {
'columns': [{'c2': {'type': 'text'}}, {'c3': {'type': 'date'}},
{'c4': {'type': 'text'}}]}})
sql = self.to_sql(inmap, stmts)
assert fix_indent(sql[0]) == "ALTER TABLE t1 ADD COLUMN c3 date"
assert fix_indent(sql[1]) == "ALTER TABLE t1 ADD COLUMN c4 text"
assert sql[2] == "ALTER TABLE t1 DROP COLUMN c1"
开发者ID:conor1984,项目名称:Pyrseas,代码行数:11,代码来源:test_column.py
示例17: test_create_rule_instead
def test_create_rule_instead(self):
"Create a rule with an INSTEAD action"
inmap = self.std_map()
inmap['schema sd'].update({'table t1': {
'columns': [{'c1': {'type': 'integer'}}, {'c2': {'type': 'text'}}],
'rules': {'r1': {'event': 'update', 'instead': True,
'actions': 'NOTHING'}}}})
sql = self.to_sql(inmap)
assert fix_indent(sql[0]) == CREATE_TABLE_STMT
assert fix_indent(sql[1]) == "CREATE RULE r1 AS ON UPDATE TO sd.t1 " \
"DO INSTEAD NOTHING"
开发者ID:perseas,项目名称:Pyrseas,代码行数:11,代码来源:test_rule.py
示例18: test_create_aggregate
def test_create_aggregate(self):
"Create a simple aggregate"
inmap = self.std_map()
inmap['schema public'].update({'function f1(integer, integer)': {
'language': 'sql', 'returns': 'integer', 'source': SOURCE2,
'volatility': 'immutable'}})
inmap['schema public'].update({'aggregate a1(integer)': {
'sfunc': 'f1', 'stype': 'integer'}})
sql = self.to_sql(inmap)
assert fix_indent(sql[1]) == CREATE_STMT2
assert fix_indent(sql[2]) == "CREATE AGGREGATE a1(integer) " \
"(SFUNC = f1, STYPE = integer)"
开发者ID:conor1984,项目名称:Pyrseas,代码行数:12,代码来源:test_function.py
示例19: test_create_event_trigger_simple
def test_create_event_trigger_simple(self):
"Create a simple event trigger"
inmap = self.std_map(plpgsql_installed=True)
inmap['schema sd'].update({'function f1()': {
'language': 'plpgsql', 'returns': 'event_trigger',
'source': FUNC_SRC}})
inmap.update({'event trigger et1': {
'enabled': True, 'event': 'ddl_command_end',
'procedure': 'sd.f1()'}})
sql = self.to_sql(inmap)
assert fix_indent(sql[0]) == CREATE_FUNC_STMT
assert fix_indent(sql[1]) == CREATE_STMT % ''
开发者ID:perseas,项目名称:Pyrseas,代码行数:12,代码来源:test_eventtrig.py
示例20: test_change_column_types
def test_change_column_types(self):
"Change the datatypes of two columns"
self.db.execute_commit(CREATE_STMT1)
inmap = self.std_map()
inmap['schema public'].update({'table t1': {
'columns': [{'c1': {'type': 'bigint'}},
{'c2': {'type': 'varchar(25)'}}]}})
dbsql = self.db.process_map(inmap)
self.assertEqual(fix_indent(dbsql[0]),
"ALTER TABLE t1 ALTER COLUMN c1 TYPE bigint")
self.assertEqual(fix_indent(dbsql[1]),
"ALTER TABLE t1 ALTER COLUMN c2 TYPE varchar(25)")
开发者ID:rdunklau,项目名称:Pyrseas,代码行数:12,代码来源:test_column.py
注:本文中的pyrseas.testutils.fix_indent函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论