def create_project(self, args): project = Project(name=args.name, dev=args.dev) if args.uid: for each in args.uid: project.add_task(self.tasks[each]) self.projects[project.uid] = project self.logger.info(f'Project {project.uid} with name {project.name} was created ')
def main(argv): exitval = 0 try: from src._argparse import CustomArgumentParser, CustomHelpFormatter parser = CustomArgumentParser( description="builds the task presenter and tutorial for the GeoTag-X projects located in the specified directories.", formatter_class=CustomHelpFormatter, add_help=False ) parser.add_argument("path", metavar="PATH", nargs='+') parser.add_argument("-c", "--compress", action="store_true", help="compresses the generated files, effectively generating smaller, albeit less readable, task presenters and tutorials.") parser.add_argument("-f", "--force", action="store_true", help="overwrites any existing task presenter and/or tutorial in the specified directory.") parser.add_argument("-h", "--help", action="help", help="prints this help message and exits.") parser.add_argument("-s", "--summarize", action="store_true", help="prints a project's overview.") parser.add_argument("-t", "--theme", nargs=1, metavar="THEME", help="sets the path to a user-defined theme.") parser.add_argument("-v", "--verbose", action="store_true", help="explains what is being done.") if len(sys.argv) < 2: parser.print_usage() exitval = 1 else: args = parser.parse_args() # Ignore all duplicate paths, including symbolic links. import os args.path = set([os.path.realpath(path) for path in args.path]) if args.summarize: for path in args.path: print Project(path) else: from src.theme import Theme from src.htmlwriter import HtmlWriter # If no path to a custom theme is specified, use the default theme. if args.theme is None: args.theme = os.path.join(os.path.dirname(os.path.realpath(__file__)), "theme") else: args.theme = args.theme[0] theme = Theme(args.theme) writer = HtmlWriter(theme, args.compress, args.force, args.verbose) for path in args.path: writable, message = writer.iswritabledir(path) if writable: project = Project(path) writer.write(project) else: print message except Exception as e: print e exitval = 1 finally: sys.exit(exitval)
def __exit__(self, exc_type, exc_val, exc_tb): if exc_type is None: cfgs, invalid = self.project.get_configurations() self.project.save() project_from_disk = Project(self.project.root) cfgs_from_disk, invalid_from_disk = project_from_disk.get_configurations( ) self.test_case.assertEqual(set(cfgs), set(cfgs_from_disk)) self.test_case.assertEqual(set(invalid), set(invalid_from_disk))
def create_project(base_url, client_id, client_secret, team_id): try: Project.create(base_url, client_id, client_secret, team_id=str(team_id), operations_path='project_configuration.json', documents_path='documents') except Exception as e: raise SystemExit(e)
def test_priority_of_student_is_ratio_of_project_keywords_matched(self): project_kws = self.n_keywords(10) student_kws = self.n_keywords(2) student_kws += self.other_keywords(37) project = Project(1, keywords=project_kws) student = Student(1, [project], keywords=student_kws) self.assertEqual(keywords_priority_calculator(student, project), 0.2)
def create_proj(self): """ desc: create a new project """ section_head("Creating New Project") while True: try: self.current_open_proj = Project(parent=self, mode="create") break except FileExistsError: err_mess( "The directory already exists and cannot be overwritten. Choose another name or location" ) self.projects[self.current_open_proj. name] = self.current_open_proj.get_data_dir() self.write_proj_file()
def test_priority_of_student_is_one_if_all_keywords_match(self): kw_1 = 'kw_1' kw_2 = 'kw_2' kw_3 = 'kw_3' kws = [kw_1, kw_2, kw_3] project = Project(1, keywords=kws) student = Student(1, [project], keywords=kws) self.assertEqual(keywords_priority_calculator(student, project), 1)
def list(self, argv): project = Project() configurations, invalid = project.get_configurations() configurations.sort(key=lambda cfg: (cfg.generator, cfg.config_name or '')) table = Table() table.set_headers('Generator', 'Configuration', 'Parameters') pad = False for generator, confs in itertools.groupby(configurations, key=lambda x: x.generator): if pad: table.add_row() for config in confs: table.add_row(config.generator, config.config_name or '(default)', config.params or '(default)') pad = True print(table)
def test_priority_of_student_is_zero_if_none_match(self): kw_1 = 'kw_1' kw_2 = 'kw_2' kw_3 = 'kw_3' kw_4 = 'kw_4' student_kws = [kw_1, kw_2] project_kws = [kw_3, kw_4] project = Project(1, keywords=project_kws) student = Student(1, [project], keywords=student_kws) self.assertEqual(keywords_priority_calculator(student, project), 0)
def create_project(self, argv): parser = argparse.ArgumentParser( description='Create a new Halide project', usage='hlgen create project <name>') parser.add_argument('name', type=str, help='The name of the project. This will also be the name of the directory created.') args = parser.parse_args(argv) project = Project.create_new(args.name) project.save()
def create_generator(self, argv): parser = argparse.ArgumentParser( description='Create a new Halide generator', usage='hlgen create generator <name>') parser.add_argument('name', type=str, help='The name of the generator. This will also be the name of the source file created.') args = parser.parse_args(argv) project = Project() project.create_generator(args.name) project.save()
def delete_configuration(self, argv): parser = argparse.ArgumentParser( description='Delete an existing Halide generator configuration', usage='''hlgen delete configuration <gen> [<name>] Recommended to run `make clean` before running this command. To remove the default configuration, either omit <name> or write '(default)'. ''') parser.add_argument('gen', help='The name of the generator.') parser.add_argument('name', help='The name of the configuration.', default=None, nargs='?') args = parser.parse_args(argv) project = Project() project.delete_configuration(args.gen, self._normalize_config_name(args.name)) project.save()
def create_configuration(self, argv): parser = argparse.ArgumentParser( description='Create a new Halide generator configuration', usage='''hlgen create configuration <gen> <name> [<params>] The new configuration will be compiled as <gen>__<name>.{a,h,so,etc.}. To restore a default configuration after deleting it either omit <name> by putting '' in its place or write '(default)' ''') parser.add_argument('gen', type=str, help='The name of the generator.') parser.add_argument('name', type=str, help='The name of the configuration.', default='', nargs='?') parser.add_argument('params', type=str, help='The build parameters passed to the generator.', nargs=argparse.REMAINDER) args = parser.parse_args(argv) project = Project() project.create_configuration(args.gen, self._normalize_config_name(args.name), args.params) project.save()
def delete_generator(self, argv): parser = argparse.ArgumentParser( description='Delete an existing Halide generator', usage='hlgen delete generator [-f/--force] <name>') parser.add_argument('-f', '--force', action='store_true', help='do not prompt for confirmation before deleting files') parser.add_argument('name', type=str, help='The name of the generator.') args = parser.parse_args(argv) can_delete = True if not args.force: response = None while response not in ['', 'y', 'yes', 'n', 'no']: print('Alert! this action will delete any associated .gen.cpp files.') response = input('Are you sure you wish to continue? [y/n] ').lower() can_delete = response in ['', 'y', 'yes'] if can_delete: project = Project() project.delete_generator(args.name) project.save()
def test_given_user_is_already_logged_in__then_user_is_logged_out(self): Project.command('login [email protected] test') msg = Project.command('logout') self.assertEqual(msg, 'Goodbye, ta one')
def test_given_a_ta_tries_emailing_someone_then_error_message_is_displayed( self): Project.command("login [email protected] test") msg = Project.command("notify [email protected] \"subject\" \"body\"") self.assertEqual(msg, "TAs cannot send notifications")
def test_given_invalid_body_argument_then_error_is_thrown(self): with self.assertRaises(ValueError): Project.command("notify [email protected] \"subject\" 1234")
def test_given_too_few_arguments_then_an_error_message_is_displayed(self): msg = Project.command("notify [email protected] \"subject\"") self.assertEqual(msg, "Not enough info for an email")
def test_given_too_few_arguments_with_an_old_user__then_user_is_not_logged_in( self): msg = Project.command('login [email protected]') self.assertEqual(msg, INVALID_LOGIN_MESSAGE)
def test_priority_split_obtained_from_supervisor(self): priority_split = 'a_split' supervisor = Supervisor(priority_split) project = Project(1, supervisor=supervisor) self.assertEqual(project.priority_split, supervisor.priority_split)
def setUp(self): Project.command("login [email protected] test")
def test_given_a_new_user_logging_in_for_the_first_time__then_the_user_is_greeted_and_told_to_enter_new_password( self): msg = Project.command('login [email protected]') self.assertEqual(msg, 'Welcome new user. Please enter your new password:')
def test_given_user_is_not_logged_in__then_error_message_is_displayed( self): msg = Project.command('logout') self.assertEqual(msg, 'There are no users to sign out')
def test_given_a_supervisor_tries_emailing_someone_then_email_is_sent( self): msg = Project.command("notify [email protected] \"subject\" \"body\"") self.assertEqual(msg, "Notification sent")
def __init__(self, test_case: TestProject): self.test_case = test_case project_name = test_case.id().split('.')[ -1] # due to https://stackoverflow.com/a/14954405/2137996 self.project = Project.create_new(project_name) test_case.assertIsNotNone(self.project)
def test_given_a_supervisor_tries_emailing_an_invalid_email_then_email_is_sent( self): msg = Project.command("notify [email protected] \"subject\" \"body\"") self.assertEqual(msg, "no@email is an invalid email")
def test_project_is_unmatched(self): project = Project(1) self.assertFalse(project.is_matched)
def test_given_too_many_arguments_then_an_error_message_is_displayed(self): msg = Project.command( "notify [email protected] \"subject\" \"body\" invalid") self.assertEqual(msg, "Too much info for one email")
def test_project_is_matched_with_student(self): project = Project(1) project.student = 'a_student' self.assertTrue(project.is_matched)
def test_given_too_many_arguments__then_user_is_not_logged_in(self): msg = Project.command('login [email protected] tests hello') self.assertEqual( msg, 'Sorry, but that is too much information for one user')