コード例 #1
0
 def test_check_wrong_schema_1(self):
     schema = load_json(
         self.get_project_data_file("vrp_solution_schema.json"))
     del schema['properties']['routes']['items']['required']
     sm = SchemaManager(schema)
     val = sm.validate_schema()
     self.assertFalse(val)
コード例 #2
0
 def test_check_wrong_schema_2(self):
     schema = load_json(
         self.get_project_data_file("vrp_solution_schema.json"))
     schema['properties']['routes']['items']['properties']['pos'][
         'type'] = 'not_a_type'
     sm = SchemaManager(schema)
     val = sm.validate_schema()
     self.assertFalse(val)
コード例 #3
0
 def test_check_wrong_schema_3(self):
     schema = load_json(
         self.get_project_data_file("vrp_solution_schema.json"))
     del schema["properties"]["routes"]["items"]["properties"]["pos"][
         "type"]
     sm = SchemaManager(schema)
     val = sm.validate_schema()
     self.assertFalse(val)
コード例 #4
0
ファイル: test_dags.py プロジェクト: baobabsoluciones/corn
 def test_try_solving_testcase(self, config=None):
     config = config or self.config
     tests = self.app.test_cases
     for pos, data in enumerate(tests):
         data_out = None
         if isinstance(data, tuple):
             # sometimes we have input and output
             data, data_out = data
         marshm = SchemaManager(
             self.app.instance.schema).jsonschema_to_flask()
         marshm().load(data)
         if data_out is not None:
             (
                 solution_data,
                 solution_check,
                 inst_checks,
                 log,
                 log_dict,
             ) = self.app.solve(data, config, data_out)
         else:
             # for compatibility with previous format
             (
                 solution_data,
                 solution_check,
                 inst_check,
                 log,
                 log_dict,
             ) = self.app.solve(data, config)
         if solution_data is None:
             raise ValueError("No solution found")
         marshm = SchemaManager(
             self.app.solution.schema).jsonschema_to_flask()
         marshm().load(solution_data)
         marshm().validate(solution_data)
         self.assertTrue(len(solution_data) > 0)
         instance = self.app.instance.from_dict(data)
         solution = self.app.solution.from_dict(solution_data)
         s = self.app.get_default_solver_name()
         experim = self.app.get_solver(s)(instance, solution)
         experim.check_solution()
         experim.get_objective()
コード例 #5
0
ファイル: api.py プロジェクト: pchtsp/cornflow-client
def get_schema(config, dag_name, schema="instance"):
    """
    Gets a schema by name from airflow server. We use the variable api.
    We transform the jsonschema into a marshmallow class

    """
    af_client = Airflow.from_config(config)
    if not af_client.is_alive():
        raise AirflowError(error="Airflow is not accessible")

    schema_json = af_client.get_one_schema(dag_name, schema)
    manager = SchemaManager(schema_json)
    return manager.jsonschema_to_flask()
コード例 #6
0
def test_schema_solution():
    instance_obj = get_test_instance("j10.mm.zip", "j102_6.mm")
    solver = get_solver("ortools")
    exp = solver(instance_obj)
    solution = exp.solve({})
    solution_dict = exp.solution.to_dict()
    file_name = os.path.join(
        os.path.dirname(__file__), "..", "DAG", "hk_2020_dag_output.json"
    )
    os.path.exists(file_name)
    with open(file_name, "r") as f:
        schema = json.load(f)
    marshmallow_obj = SchemaManager(schema).jsonschema_to_flask()
    data = marshmallow_obj().load(solution_dict)
コード例 #7
0
    def test_to_excel3(self):
        path = self.get_data_file("../../data/empty_schema.json")
        schema = SchemaManager.load_json(path)
        schema["properties"] = dict(configuration=dict(
            type="object",
            properties=dict(option1=dict(type="integer"),
                            option2=dict(type="string")),
        ))
        sm = SchemaManager(schema)
        template = sm.to_template()
        import pandas as pd

        dataframes = {
            k: pd.DataFrame.from_dict(v)
            for k, v in template.items()
        }
        self.assertEqual(len(dataframes["configuration"]), 2)
        self.assertEqual(dataframes["configuration"].iloc[1, 1], "string")
        self.assertEqual(dataframes["configuration"].iloc[0, 1], 1)
        self.assertEqual(dataframes["_README"].shape, (1, 2))
        self.assertEqual(dataframes["_TYPES"].shape, (2, 3))
コード例 #8
0
from cornflow_client import SchemaManager, get_pulp_jsonschema
import os

fileDir = os.path.dirname(__file__)

manager = SchemaManager(get_pulp_jsonschema())

DataSchema = manager.jsonschema_to_flask()