def test_write_string(self): d = OrderedDict([("the", "a"), ("order", "z"), ("is", "b"), ("important", "y")]) string = yaml.dump(d) loaded = yaml.load(string) assert type(loaded) == OrderedDict assert loaded.keys() == ["the", "order", "is", "important"]
def test_write_ordereddict(self): d = OrderedDict([("the", "a"), ("order", "z"), ("is", "b"), ("important", "y")]) yaml.dump(d, open(os.path.join(self.dir_path, "output.yaml"), "w")) loaded = yaml.load(open(os.path.join(self.dir_path, "output.yaml"), "r")) assert type(loaded) == OrderedDict assert loaded.keys() == ["the", "order", "is", "important"]
def test_load_string(self): loaded = yaml.load(""" the: a order: z of: b the_: y keys: c is: x important: d """) assert type(loaded) == OrderedDict assert loaded.keys() == ["the", "order", "of", "the_", "keys", "is", "important"]
def test_load_ordereddict(self): open(os.path.join(self.dir_path, "input.yaml"), "w").write(""" the: a order: z of: b the_: y keys: c is: x important: d """) loaded = yaml.load(open(os.path.join(self.dir_path, "input.yaml"), "r")) assert type(loaded) == OrderedDict assert loaded.keys() == ["the", "order", "of", "the_", "keys", "is", "important"]
test_dir_number = 0 while(True): if not os.path.exists(os.path.join(args.testdir, str(test_dir_number))): os.mkdir(os.path.join(args.testdir, str(test_dir_number))) break else: test_dir_number += 1 test_dir = os.path.join(args.testdir, str(test_dir_number)) for folder in ["input", "output", "tests", ".internal", ".internal/input"]: os.mkdir(os.path.join(test_dir, folder)) problem_ids = {} try: data = yaml.load(open(os.path.join(args.task, 'task.yaml')))["problems"] for key, value in data.iteritems(): if value["type"] == "code" and "boxes" in value: for box in value["boxes"]: if value["boxes"][box]["type"] not in ["text", "file"]: problem_ids[key+"/"+box] = False elif value["boxes"][box]["type"] == "file": problem_ids[key + "/" + box] = True elif value["type"] == "code-file": problem_ids[key] = True else: problem_ids[key] = False except: print "Cannot read task.yaml!" exit(1)