def generate_test( library_name: str, root: Path, by_binding: Dict[Binding, Transition]): """ Generate the source files for a source compatibility test library_name: The FIDL library name used for this test's FIDL files. The full library name will be fidl.test.[library_name] root: root path where all files should be emitted. by_binding: Describes the test: contains the Transition for each Binding. """ steps = weave_steps(library_name, by_binding) print(white(f'Generating test to: {root}')) for step in steps: step.run(root)
def regen(args): tests = args.tests or find_tests(args.root) for name in tests: print(f'Regenerating files for {name}') test_dir = Path(os.path.join(args.root, name)) with open(test_dir / TEST_FILE, 'r') as f: test = CompatTest.fromdict(json.load(f)) generate_test.regen_files(test_dir, test) if not tests: print_warning('No tests found') else: print( white('Done! Run fx-format to get rid of formatting differences.'))
def step(test_root: Path, state: State) -> State: """ Runs a set of prompts for the user to define a single step in the transition. A step is defined as either a change to the bindings, or a change to the FIDL library (or setting up the initial state of the test). """ # New test, run setup if state is None: print(white('Step 0: Define initial FIDL and source states')) (new_test, starting_fidl) = run_test_setup(test_root) return TransitionState(test=new_test, step_kind=None, step_num=0, prev_fidl=starting_fidl, prev_srcs={ b: s.starting_src for b, s in new_test.bindings.items() }) # Initial states have been defined, but we don't know if the first step # should be a FIDL change or a bindings change. elif state.step_kind is None: print( white( f'Step 0.5: Define whether the first step is a FIDL change or binding change' )) return TransitionState(test=state.test, step_kind=read_step_kind(), step_num=1, prev_fidl=state.prev_fidl, prev_srcs=state.prev_srcs) # Change the FIDL library elif state.step_kind == StepKind.FIDL: print(white(f'Step {state.step_num}: Define next FIDL library state')) new_test = state.test fidl_name = input( f'Enter name for next {pink("FIDL")} file (e.g. "during.test.fidl"): ' ) fidl_name = prepend_step(fidl_name, state.step_num) scaffolding.add_file(test_root / FIDL_DIR, state.prev_fidl, fidl_name) # for FIDL changes, we add a FidlDef entry, and then reference it in every # binding's sequence of steps. new_fidl = state.test.fidl fidl_ref: FidlRef = stem(fidl_name) new_fidl[fidl_ref] = FidlDef(source=f'{FIDL_DIR}/{fidl_name}', instructions=read_instructions()) for binding in new_test.bindings: new_test.bindings[binding].steps.append( FidlStep(step_num=state.step_num, fidl=fidl_ref)) return TransitionState(test=new_test, step_kind=StepKind.BINDING, step_num=state.step_num + 1, prev_fidl=fidl_name, prev_srcs=state.prev_srcs) # Change the bindings else: print( white( f'Step {state.step_num}: Define next state for each binding')) new_test = state.test prev_srcs = {} for binding in new_test.bindings: filename = input( f'Enter name for next {pink(binding)} file (e.g. "during.{EXTENSIONS[binding]}") or leave empty to skip: ' ) if not filename: continue filename = prepend_step(filename, state.step_num) path: RelativePath = f'{binding}/{filename}' scaffolding.add_file(test_root, state.prev_srcs[binding], path) prev_srcs[binding] = path # for binding source changes, we append a new SourceStep to the list of steps new_test.bindings[binding].steps.append( SourceStep(step_num=state.step_num, source=path, instructions=read_instructions())) return TransitionState(test=new_test, step_kind=StepKind.FIDL, step_num=state.step_num + 1, prev_fidl=state.prev_fidl, prev_srcs=prev_srcs)
# Get the necessary modules for this remix. from util import red, white from random import randint # Get a random integer from 1 to 100 twice, in order to add them together. a = randint(1, 100) b = randint(1, 100) # Ask what they wish to be called, used below. c = input("What is your name? ") # Using the name from above, say hi in white and red. print(white("Hello, ") + red(c)) # State the calculation as they don't know it. print(red(a) + " " + red(b)) # State it with text. print(red(a), 'and', red(b)) # Nothing to see here from os import system go = input("Go back to main file? (Y/N)\n") system('clear') system('python3 main.py')
def describe(args): root = Path(os.path.join(args.root, args.name)) transitions_by_binding = read_transitions(root) print(white(f'Parameters for test {args.name}:')) print(to_flags(transitions_by_binding))
from os import system from util import red, white remixes = [ "Output using print", "Simple Math using Pre-determined Integers and Variables", "Simple Math using Input() and Variables", "Testing" ] for i in remixes: print(red(remixes.index(i) + 1) + " - " + red(i)) game = input( white("With this in mind, pick a variable from ") + red("1") + white(" to ") + red(str(len(remixes)) + "\n")) if game.isdigit(): if int(game) > 0 and int(game) < len(remixes) + 1: system('clear') system('python3 remix' + game + '.py') else: print("I don't think", red(game), "is a number from " + red("1") + " - " + red(str(len(remixes)))) goBack = input(red("Go back?") + "\n") system('clear') system('python3 main.py') else: print("I do not believe", red(game), "is a number.")