def test_relative_path(self): """Check if the set-schema and add subcommands convert relative paths from the cmdline to absolute paths in the config file. """ try: cmd = ['semantic', 'set-schema', 'dummy_project', './foo.yaml'] subprocess.check_call(cmd, env=self.testenv) self.assertTrue(op.isabs(pr.get_default_specfile('dummy_project'))) pr.remove_project("dummy_project") cmd = ['semantic', 'add', 'dummy_project', './foo.yaml'] subprocess.check_call(cmd, env=self.testenv) self.assertTrue(op.isabs(pr.get_default_specfile('dummy_project'))) finally: pr.remove_project("dummy_project_1")
def test_add_project(self): """Test if adding a project works properly.""" test_project_name = "test_project" pr.add_project(test_project_name, TEST_DATA_DICT) # Check if the project name is indeed present in the config file test_dict = pr.get_default_specfile(test_project_name) self.assertTrue(test_dict, TEST_DATA_DICT)
def test_relative_path(self): """Check if the set-schema and add subcommands convert relative paths from the cmdline to absolute paths in the config file. """ try: cmd = ['semantic', 'set-schema', 'dummy_project', './foo.yaml'] subprocess.check_call(cmd, env=self.testenv) self.assertTrue(op.isabs(pr.get_default_specfile( 'dummy_project'))) pr.remove_project("dummy_project") cmd = ['semantic', 'add', 'dummy_project', './foo.yaml'] subprocess.check_call(cmd, env=self.testenv) self.assertTrue(op.isabs(pr.get_default_specfile( 'dummy_project'))) finally: pr.remove_project("dummy_project_1")
def test_set_schema_fpath(self): """Test if programmatically setting a schema file to an existing project works.""" old_schempath = pr.get_default_specfile("pysemantic") try: self.assertTrue(pr.set_schema_fpath("pysemantic", "/foo/bar")) self.assertEqual(pr.get_default_specfile("pysemantic"), "/foo/bar") self.assertRaises(MissingProject, pr.set_schema_fpath, "foobar", "/foo/bar") finally: conf_path = pr.locate_config_file() parser = RawConfigParser() parser.read(conf_path) parser.remove_option("pysemantic", "specfile") parser.set("pysemantic", "specfile", old_schempath) with open(TEST_CONFIG_FILE_PATH, "w") as fileobj: parser.write(fileobj)
def test_loader_default_location(self): """Test if the config looks for the files in the correct places.""" # Put the test config file in the current and home directories, with # some modifications. cwd_file = op.join(os.getcwd(), "test.conf") home_file = op.join(op.expanduser('~'), "test.conf") try: self.testParser.set("pysemantic", "specfile", os.getcwd()) with open(cwd_file, "w") as fileobj: self.testParser.write(fileobj) specfile = pr.get_default_specfile("pysemantic") self.assertEqual(specfile, os.getcwd()) os.unlink(cwd_file) self.testParser.set("pysemantic", "specfile", op.expanduser('~')) with open(home_file, "w") as fileobj: self.testParser.write(fileobj) specfile = pr.get_default_specfile("pysemantic") self.assertEqual(specfile, op.expanduser('~')) finally: os.unlink(home_file)
def test_set_schema(self): """Test if the set-schema subcommand works.""" cmd = ['semantic', 'set-schema', 'dummy_project', '/tmp/baz.yaml'] subprocess.check_call(cmd, env=self.testenv) self.assertEqual(pr.get_default_specfile('dummy_project'), '/tmp/baz.yaml')