Functions | |
def | same_gdx_dump (ws, gdxfile, expected_result) |
def | check_alias_logic (prefix, db) |
Variables | |
str | GDX_DUMP2 |
str | GDX_DUMP1 |
str | GAMS_DATA |
sys | sys_dir = sys.argv[1] if len(sys.argv) > 1 else None |
GamsWorkspace | ws = GamsWorkspace(system_directory=sys_dir) |
GamsWorkspace | job = ws.add_job_from_string(GAMS_DATA) |
GamsWorkspace | db = ws.add_database(source_database=job.out_db) |
GamsWorkspace | db2 = ws.add_database() |
GamsWorkspace | ii = db2.add_set_dc(db["ii"].name, ["*"], db["ii"].text) |
GamsWorkspace | aa_orig = db["aa"] |
GamsWorkspace | aa = db2.add_parameter_dc(db["aa"].name, [ii], db["aa"].text) |
Function Documentation
◆ check_alias_logic()
def alias.check_alias_logic | ( | prefix, | |
db | |||
) |
Definition at line 109 of file alias.py.
109def check_alias_logic(prefix, db):
110 # check number of symbols
111 if len(db) != 5:
112 raise Exception(
113 f"GamsDatabase '{prefix}' should have five symbols: i, j, ij, a, aa."
114 )
115
116 # check retrival of alias sets
117 if db["ii"].name != "i":
118 raise Exception(f"{prefix}: We should get set 'i' when asking for alias 'ii'.")
119 if db["jj"].name != "j":
120 raise Exception(f"{prefix}: We should get set 'j' when asking for alias 'jj'.")
121 if db["iijj"].name != "ij":
122 raise Exception(
123 f"{prefix}: We should get set 'ij' when asking for alias 'iijj'."
124 )
125
126 # check domain logic
127 if not db.check_domains():
128 raise Exception(f"{prefix}: Check domains should be true.")
129 if not isinstance(db["aa"].domains[0], GamsSet):
130 raise Exception(f"{prefix}: domains[0] of 'aa' should be a set.")
131 if db["aa"].domains[0].name != "i":
132 raise Exception(f"{prefix}: domains[0] of 'aa' should be 'i'.")
133
134 db["ii"].delete_record("i1")
135 if db.check_domains():
136 raise Exception(
137 f"{prefix}: check_domains() should be False after removal of 'i1'."
138 )
139 db["ii"].add_record("i1")
140 if not db.check_domains():
141 raise Exception(
142 f"{prefix}: check_domains() should be True after adding 'i1' again."
143 )
144
145
◆ same_gdx_dump()
def alias.same_gdx_dump | ( | ws, | |
gdxfile, | |||
expected_result | |||
) |
Definition at line 91 of file alias.py.
91def same_gdx_dump(ws, gdxfile, expected_result):
92 result = ""
93 cmd = [
94 os.path.join(ws.system_directory, "gdxdump"),
95 os.path.join(ws.working_directory, gdxfile),
96 ]
97 p = subprocess.Popen(
98 cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE
99 )
100 result, error = p.communicate()
101 if error:
102 raise Exception(error)
103 result = result.decode()
104 return re.sub(r"\s", "", result.lower()) == re.sub(
105 r"\s", "", expected_result.lower()
106 )
107
108
Variable Documentation
◆ aa
◆ aa_orig
◆ db
GamsWorkspace alias.db = ws.add_database(source_database=job.out_db) |
◆ db2
◆ GAMS_DATA
str alias.GAMS_DATA |
◆ GDX_DUMP1
◆ GDX_DUMP2
str alias.GDX_DUMP2 |
◆ ii
◆ job
GamsWorkspace alias.job = ws.add_job_from_string(GAMS_DATA) |
◆ sys_dir
sys alias.sys_dir = sys.argv[1] if len(sys.argv) > 1 else None |