def test_program_to_api(): uni = University(query_db) deg = uni.find_degree_number_code('3778 COMPA1', 2020) assert deg is not None prog = Generator(deg, uni).generate() assert isinstance(prog, Program) api = prog.to_api() # print('=======> api') # print(api) assert api['id'] == '3778 COMPA1' assert api['name'] == 'Computer Science' assert api['year'] == 2020 assert api['duration'] == 3 assert api[ 'url'] == 'https://www.handbook.unsw.edu.au/undergraduate/programs/2020/3778' enrollments = api['enrollments'] # visually check that enrollments are sorted print('=====> TODO visually check enrollments are sorted') print(enrollments)
def test_empty_year(): uni = University(query_db) deg = uni.find_degree_number_code('3778 COMPA1', 2020) assert deg is not None prog = Generator(deg, uni).generate() # remove COMP2511, COMP3121, COMP4920, the only things in 2021 comp2511 = None comp3121 = None comp4920 = None for enr in prog.courses: if enr.course.course_code == 'COMP2511': comp2511 = enr elif enr.course.course_code == 'COMP3121': comp3121 = enr elif enr.course.course_code == 'COMP4920': comp4920 = enr prog.remove_course(comp2511) prog.remove_course(comp3121) prog.remove_course(comp4920) # put COMP4920 in T3 prog.add_course(comp4920.course, Term(2022, 3)) # get the api api = prog.to_api() assert api['id'] == '3778 COMPA1' assert api['name'] == 'Computer Science' assert api['year'] == 2020 assert api['duration'] == 3 assert api[ 'url'] == 'https://www.handbook.unsw.edu.au/undergraduate/programs/2020/3778' enrollments = api['enrollments'] print('=========== enrollments ===========') print(api) print(enrollments) print('--------------------') # you should still have empty information in API for T2 2021 plan_2021 = enrollments[1] assert plan_2021['year'] == 2021 assert len(plan_2021['term_plans']) == 3 assert len(plan_2021['term_plans'][0]['course_ids']) == 0 assert len(plan_2021['term_plans'][1]['course_ids']) == 0 assert len(plan_2021['term_plans'][2]['course_ids']) == 0
def plan(): ''' Returns the default program returned by Generator on our current db for 3778 program ''' uni = University(query_db) deg = uni.find_degree_number_code('3778 COMPA1', 2020) assert deg is not None prog = Generator(deg, uni).generate() assert isinstance(prog, Program) return prog
def generate_program(code: str, year: int) -> str: ''' Generates a program plan for the given degree code, ''' uni = University(query_db) year = int(year) deg = uni.load_degree(code, year=year) if deg is None: # given code is not valid # TODO see if there's a more elegant way of doing this raise Exception(f'Degree code {code} is not in the database for year {year}.') gen = Generator(deg, uni) return jsonify(gen.generate().get_generator_response_api())
'language': None } # Read settings. for line in lines_settings: split = line.split('=') setting = split[0].strip().strip('"') value = split[1].strip().strip('"') if setting in settings: settings[setting] = value logging.info('[__init__] Acquired setting "%s" with value "%s"' % (setting, value)) else: logging.info('[__init__] Ignoring unexpected setting "%s"' % (setting)) # Get language. locale_path = os.path.join(package_dir, 'locales') logging.info('[__init__] locale path: %s' % (locale_path)) if settings['language'] != None: lang = gettext.translation('base', locale_path, [settings['language']]) else: lang = gettext.translation('base', locale_path, ['en']) lang.install() _ = lang.gettext # Begin process. Generator(settings['source_content_dir'], settings['destination_content_dir'], settings['template_dir'], settings['language'])
#!/usr/bin/python import os import shutil import subprocess import re from classes.generator import Generator from classes.analyze import Analyze from classes.parser import Parser __DIR__ = os.path.curdir __xsd_path__ = __DIR__ + "./xsd2code/Xsd2Code.exe" if __name__ == "__main__": try: if not os.path.exists(__xsd_path__): raise FileNotFoundError( "xsd2Code didn't exists! Check folder 'xsd2code' in current dir!" ) generator = Generator() generator.run() except Exception as e: print("Error message: " + e.args[0]) exit(-1) print("Done!")