def test_from_specfile(self):
     """Test if the SchemaValidator.from_specfile constructor works."""
     validator = SchemaValidator.from_specfile(self.specfile, "iris")
     self.assertKwargsEqual(validator.get_parser_args(),
                            self.ideal_iris_parser_args)
     validator = SchemaValidator.from_specfile(self.specfile,
                                               "person_activity")
     self.assertKwargsEqual(validator.get_parser_args(),
                            self.ideal_activity_parser_args)
 def test_from_specfile(self):
     """Test if the SchemaValidator.from_specfile constructor works."""
     validator = SchemaValidator.from_specfile(self.specfile, "iris")
     self.assertKwargsEqual(validator.get_parser_args(),
                            self.ideal_iris_parser_args)
     validator = SchemaValidator.from_specfile(self.specfile,
                                               "person_activity")
     self.assertKwargsEqual(validator.get_parser_args(),
                            self.ideal_activity_parser_args)
Beispiel #3
0
    def _init_validate(self, dataset_name):
        """Given a dataset name, create a SchemaValidator object and add to the
        cache.

        :param dataset_name: Name of the dataset
        """
        specs = self.specifications.get(dataset_name)
        is_pickled = specs.get("pickle", False)
        if self.specfile is not None:
            validator = SchemaValidator.from_specfile(specfile=self.specfile,
                                                      name=dataset_name,
                                                      is_pickled=is_pickled)
        else:
            validator = SchemaValidator(specification=specs,
                                        name=dataset_name,
                                        is_pickled=is_pickled)
        self.validators[dataset_name] = validator
 def test_pickled_arguments(self):
     """Test if the SchemaValidator correctly loads pickled arguments."""
     tempdir = tempfile.mkdtemp()
     outpath = op.join(tempdir, "iris_args.pkl")
     with open(outpath, 'w') as fid:
         cPickle.dump(self.ideal_iris_parser_args, fid)
     new_schema_path = op.join(tempdir, "pickle_schema.yml")
     with open(new_schema_path, 'w') as fid:
         yaml.dump(dict(iris=dict(pickle=outpath)), fid, Dumper=Dumper,
                   default_flow_style=False)
     org_data = pd.read_csv(self.ideal_iris_parser_args['filepath_or_buffer'])
     try:
         validator = SchemaValidator.from_specfile(new_schema_path, "iris",
                                                   is_pickled=True)
         loaded = pd.read_csv(**validator.get_parser_args())
         self.assertDataFrameEqual(loaded, org_data)
     finally:
         shutil.rmtree(tempdir)
 def test_pickled_arguments(self):
     """Test if the SchemaValidator correctly loads pickled arguments."""
     tempdir = tempfile.mkdtemp()
     outpath = op.join(tempdir, "iris_args.pkl")
     with open(outpath, 'w') as fid:
         cPickle.dump(self.ideal_iris_parser_args, fid)
     new_schema_path = op.join(tempdir, "pickle_schema.yml")
     with open(new_schema_path, 'w') as fid:
         yaml.dump(dict(iris=dict(pickle=outpath)),
                   fid,
                   Dumper=Dumper,
                   default_flow_style=False)
     org_data = pd.read_csv(
         self.ideal_iris_parser_args['filepath_or_buffer'])
     try:
         validator = SchemaValidator.from_specfile(new_schema_path,
                                                   "iris",
                                                   is_pickled=True)
         loaded = pd.read_csv(**validator.get_parser_args())
         self.assertDataFrameEqual(loaded, org_data)
     finally:
         shutil.rmtree(tempdir)