Ejemplo n.º 1
0
 def test_report_type_casting(
     self,
     rec_id,
     val,
     config_file_path,
     schema_file_path,
     results_file_path,
     backend,
     success,
 ):
     args = dict(schema_path=schema_file_path, namespace="test")
     backend_data = ({
         "config": config_file_path
     } if backend == "db" else {
         "results_file_path": results_file_path
     })
     args.update(backend_data)
     psm = PipestatManager(**args)
     if success:
         psm.report(
             record_identifier=rec_id,
             values=val,
             strict_type=False,
             force_overwrite=True,
         )
     else:
         with pytest.raises((ValidationError, TypeError)):
             psm.report(
                 record_identifier=rec_id,
                 values=val,
                 strict_type=False,
                 force_overwrite=True,
             )
Ejemplo n.º 2
0
    def test_report_requires_schema(
        self,
        rec_id,
        val,
        config_no_schema_file_path,
        results_file_path,
        backend,
    ):
        """
        If schema is not provided at object instantiation stage, SchemaNotFondError
        is raised if report method is called with file as a backend.

        In case of the DB as a backend, the error is raised at object
        instantiation stage since there is no way to init relational DB table
        with no columns predefined
        """
        args = dict(namespace="test")
        backend_data = ({
            "config": config_no_schema_file_path
        } if backend == "db" else {
            "results_file_path": results_file_path
        })
        args.update(backend_data)
        psm = PipestatManager(**args)
        if backend == "file":
            with pytest.raises(SchemaNotFoundError):
                psm.report(record_identifier=rec_id, values=val)
Ejemplo n.º 3
0
 def test_report_requires_schema(self, results_file_path):
     """ Report fails if schema not provided, even for a file backend """
     psm = PipestatManager(name="test", results_file=results_file_path)
     with pytest.raises(SchemaNotFoundError):
         psm.report(result_identifier="name_of_something",
                    record_identifier="sample1",
                    value="test_name")
Ejemplo n.º 4
0
 def test_report_basic(self, rec_id, res_id, val, config_file_path,
                       schema_file_path, results_file_path, backend):
     args = dict(schema_path=schema_file_path, name="test")
     backend_data = {"database_config": config_file_path} if backend == "db"\
         else {"results_file": results_file_path}
     args.update(backend_data)
     psm = PipestatManager(**args)
     psm.report(result_identifier=res_id,
                record_identifier=rec_id,
                value=val)
     assert rec_id in psm.data["test"]
     assert res_id in psm.data["test"][rec_id]
     if backend == "file":
         is_in_file(results_file_path, str(val))
Ejemplo n.º 5
0
 def test_report(
     self,
     val,
     config_file_path,
     schema_file_path,
 ):
     REC_ID = "constant_record_id"
     psm = PipestatManager(
         schema_path=schema_file_path,
         namespace="test",
         record_identifier=REC_ID,
         database_only=True,
         config=config_file_path,
     )
     psm.report(values=val)
     assert len(psm.data) == 0
     val_name = list(val.keys())[0]
     assert psm.select(filter_conditions=[(val_name, "eq", str(val[val_name]))])
Ejemplo n.º 6
0
 def test_report(self, val, config_file_path, schema_file_path,
                 results_file_path, backend):
     REC_ID = "constant_record_id"
     args = dict(
         schema_path=schema_file_path,
         namespace="test",
         record_identifier=REC_ID,
         database_only=False,
     )
     backend_data = ({
         "config": config_file_path
     } if backend == "db" else {
         "results_file_path": results_file_path
     })
     args.update(backend_data)
     psm = PipestatManager(**args)
     psm.report(values=val)
     assert REC_ID in psm.data["test"]
     assert list(val.keys())[0] in psm.data["test"][REC_ID]
     if backend == "file":
         is_in_file(results_file_path, str(list(val.values())[0]))
Ejemplo n.º 7
0
 def test_report_overwrite(
     self,
     rec_id,
     val,
     config_file_path,
     schema_file_path,
     results_file_path,
     backend,
 ):
     args = dict(schema_path=schema_file_path,
                 namespace="test",
                 database_only=False)
     backend_data = ({
         "config": config_file_path
     } if backend == "db" else {
         "results_file_path": results_file_path
     })
     args.update(backend_data)
     psm = PipestatManager(**args)
     psm.report(record_identifier=rec_id, values=val, force_overwrite=True)
     assert rec_id in psm.data["test"]
     assert list(val.keys())[0] in psm.data["test"][rec_id]
     if backend == "file":
         is_in_file(results_file_path, str(list(val.values())[0]))