예제 #1
0
 def get_course_descriptor_content(self, courseid):
     """
     :param courseid: the course id of the course
     :raise InvalidNameException, CourseNotFoundException, CourseUnreadableException
     :return: the content of the dict that describes the course
     """
     return load_json_or_yaml(self._get_course_descriptor_path(courseid))
예제 #2
0
 def test_yaml_read(self):
     open(os.path.join(self.dir_path, "input.yaml"), "w").write("""
     key1: data1
     key2:
         key3:
             - 1
             - 2
     """)
     assert load_json_or_yaml(os.path.join(self.dir_path, "input.yaml")) == {'key1': 'data1', 'key2': {'key3': [1, 2]}}
 def test_json_read(self):
     with open(os.path.join(self.dir_path, "input.json"), "w") as f:
         f.write('{"key1":"data1","key2":{"key3":[1,2]}}')
     assert load_json_or_yaml(os.path.join(self.dir_path,
                                           "input.json")) == {
                                               'key1': 'data1',
                                               'key2': {
                                                   'key3': [1, 2]
                                               }
                                           }
예제 #4
0
 def test_yaml_read(self):
     with open(os.path.join(self.dir_path, "input.yaml"), "w") as f:
         f.write("""
         key1: data1
         key2:
             key3:
                 - 1
                 - 2
         """)
     assert load_json_or_yaml(os.path.join(self.dir_path, "input.yaml")) == {'key1': 'data1', 'key2': {'key3': [1, 2]}}
예제 #5
0
 def _update_cache(self, courseid):
     """
     Updates the cache
     :param courseid: the (valid) course id of the course
     :raise InvalidNameException, CourseNotFoundException, CourseUnreadableException
     """
     path_to_descriptor = self._get_course_descriptor_path(courseid)
     try:
         course_descriptor = load_json_or_yaml(path_to_descriptor)
     except Exception as e:
         raise CourseUnreadableException(str(e))
     self._cache[courseid] = (self._course_class(courseid, course_descriptor, self._task_factory), os.stat(path_to_descriptor).st_mtime)
     self._task_factory.update_cache_for_course(courseid)
 def test_yaml_write(self):
     write_json_or_yaml(os.path.join(self.dir_path, "output.yaml"), {
         'key1': 'data1',
         'key2': {
             'key3': [1, 2]
         }
     })
     assert load_json_or_yaml(os.path.join(self.dir_path,
                                           "output.yaml")) == {
                                               'key1': 'data1',
                                               'key2': {
                                                   'key3': [1, 2]
                                               }
                                           }
예제 #7
0
 def test_yaml_write(self):
     write_json_or_yaml(os.path.join(self.dir_path, "output.yaml"), {'key1': 'data1', 'key2': {'key3': [1, 2]}})
     assert load_json_or_yaml(os.path.join(self.dir_path, "output.yaml")) == {'key1': 'data1', 'key2': {'key3': [1, 2]}}
예제 #8
0
 def test_json_read(self):
     open(os.path.join(self.dir_path, "input.json"), "w").write('{"key1":"data1","key2":{"key3":[1,2]}}')
     assert load_json_or_yaml(os.path.join(self.dir_path, "input.json")) == {'key1': 'data1', 'key2': {'key3': [1, 2]}}