def test_get_datasets_no_project(self): """Test if the get_datasets function works with no project name.""" dataset_names = pr.get_datasets() self.assertTrue("pysemantic" in dataset_names) ideal = ['person_activity', 'multi_iris', 'iris', 'bad_iris', 'random_row_iris'] self.assertItemsEqual(dataset_names['pysemantic'], ideal)
def test_list_datasets(self): """Test if the `list` subocmmand works for listing datasets.""" command = "semantic list --project pysemantic" cmd = command.split(' ') datasets = pr.get_datasets("pysemantic") output = subprocess.check_output(cmd, env=self.testenv).splitlines() self.assertItemsEqual(datasets, output)
def test_get_datasets(self): """Test the get_datasets function returns the correct datasets.""" datasets = pr.get_datasets("pysemantic") ideal = [ 'person_activity', 'multi_iris', 'iris', 'bad_iris', 'random_row_iris' ] self.assertItemsEqual(ideal, datasets)
def test_get_datasets_no_project(self): """Test if the get_datasets function works with no project name.""" dataset_names = pr.get_datasets() self.assertTrue("pysemantic" in dataset_names) ideal = [ 'person_activity', 'multi_iris', 'iris', 'bad_iris', 'random_row_iris' ] self.assertItemsEqual(dataset_names['pysemantic'], ideal)
def cli(arguments): """cli - The main CLI argument parser. :param arguments: command line arguments, as parsed by docopt :type arguments: dict :return: None """ if arguments.get("list", False): if arguments["--project"] is None: pr.view_projects() else: proj_name = arguments.get("--project") dataset_names = pr.get_datasets(proj_name) for name in dataset_names: print name elif arguments.get("add", False): proj_name = arguments.get("PROJECT_NAME") proj_spec = arguments.get("PROJECT_SPECFILE") proj_spec = op.abspath(proj_spec) pr.add_project(proj_name, proj_spec) elif arguments.get("remove", False): proj_name = arguments.get("PROJECT_NAME") if arguments["--dataset"] is None: if not pr.remove_project(proj_name): print "Removing the project {0} failed.".format(proj_name) else: pr.remove_dataset(proj_name, arguments["--dataset"]) elif arguments.get("set-schema", False): try: proj_name = arguments.get("PROJECT_NAME") proj_spec = arguments.get("SCHEMA_FPATH") proj_spec = op.abspath(proj_spec) pr.set_schema_fpath(proj_name, proj_spec) except MissingProject: msg = """Project {} not found in the configuration. Please use $ semantic add to register the project.""".format( arguments.get("PROJECT_NAME") ) print msg elif arguments.get("set-specs", False): proj_name = arguments.get("PROJECT_NAME") dataset_name = arguments.get("--dataset") newspecs = {} if arguments.get("--path", False): newspecs["path"] = arguments.get("--path") if arguments.get("--dlm", False): newspecs["delimiter"] = arguments.get("--dlm") pr.set_schema_specs(proj_name, dataset_name, **newspecs) elif arguments.get("add-dataset", False): proj_name = arguments.get("--project") dataset_name = arguments.get("DATASET_NAME") specs = dict(path=arguments["--path"], delimiter=arguments["--dlm"]) pr.add_dataset(proj_name, dataset_name, specs) elif arguments.get("export", False): project = pr.Project(arguments.get("PROJECT_NAME")) project.export_dataset(arguments.get("--dataset"), outpath=arguments.get("OUTPATH"))
def cli(arguments): """cli - The main CLI argument parser. :param arguments: command line arguments, as parsed by docopt :type arguments: dict :return: None """ if arguments.get("list", False): if arguments['--project'] is None: pr.view_projects() else: proj_name = arguments.get('--project') dataset_names = pr.get_datasets(proj_name) for name in dataset_names: print name elif arguments.get("add", False): proj_name = arguments.get("PROJECT_NAME") proj_spec = arguments.get("PROJECT_SPECFILE") proj_spec = op.abspath(proj_spec) pr.add_project(proj_name, proj_spec) elif arguments.get("remove", False): proj_name = arguments.get("PROJECT_NAME") if arguments['--dataset'] is None: if not pr.remove_project(proj_name): print "The project {0} doesn't exist.".format(proj_name) else: pr.remove_dataset(proj_name, arguments['--dataset']) elif arguments.get("set-schema", False): try: proj_name = arguments.get("PROJECT_NAME") proj_spec = arguments.get("SCHEMA_FPATH") proj_spec = op.abspath(proj_spec) pr.set_schema_fpath(proj_name, proj_spec) except MissingProject: msg = """Project {} not found in the configuration. Please use $ semantic add to register the project.""".format(arguments.get("PROJECT_NAME")) print msg elif arguments.get("set-specs", False): proj_name = arguments.get("PROJECT_NAME") dataset_name = arguments.get("--dataset") newspecs = {} if arguments.get("--path", False): newspecs['path'] = arguments.get("--path") if arguments.get("--dlm", False): newspecs['delimiter'] = arguments.get("--dlm") pr.set_schema_specs(proj_name, dataset_name, **newspecs) elif arguments.get("add-dataset", False): proj_name = arguments.get('--project') dataset_name = arguments.get("DATASET_NAME") specs = dict(path=arguments["--path"], delimiter=arguments["--dlm"]) pr.add_dataset(proj_name, dataset_name, specs) elif arguments.get("export", False): project = pr.Project(arguments.get("PROJECT_NAME")) project.export_dataset(arguments.get("--dataset"), outpath=arguments.get("OUTPATH"))
def test_remove_dataset(self): """Test if removing datasets works from the command line.""" # Add a temporary dataset and try to remove it. tempdir = tempfile.mkdtemp() outfile = op.join(tempdir, "testdata.csv") dframe = pd.DataFrame(np.random.random((10, 2)), columns=['a', 'b']) dframe.to_csv(outfile, index=False) specs = dict(path=outfile, delimiter=',') pr.add_dataset("pysemantic", "testdata", specs) try: command = "semantic remove pysemantic --dataset testdata" cmd = command.split(' ') subprocess.check_call(cmd, env=self.testenv) datasets = pr.get_datasets("pysemantic") self.assertNotIn("testdata", datasets) finally: datasets = pr.get_datasets("pysemantic") if "testdata" in datasets: pr.remove_dataset("pysemantic", "testdata") shutil.rmtree(tempdir)
def test_get_datasets(self): """Test the get_datasets function returns the correct datasets.""" datasets = pr.get_datasets("pysemantic") ideal = ['person_activity', 'multi_iris', 'iris', 'bad_iris', 'random_row_iris'] self.assertItemsEqual(ideal, datasets)