Exemple #1
0
 def test_random_hint_context(self):
     """Trying to load file with random content. Expecting HintFormatError exception riseing """
     hints_file_name = 'test/hintfiles/random.hints'
     if not os.path.exists(hints_file_name):
         logging.error("Hint file %s not found", hints_file_name)
         return
     HintFile.load_json(test._current_view, hints_file_name)
Exemple #2
0
 def test_wrong_data_format_hint(self):
     """Trying to load file with wrong data format"""
     hints_file_name = 'test/hintfiles/wrong_data_format.hints'
     if not os.path.exists(hints_file_name):
         logging.error("Hint file %s not found", hints_file_name)
         return
     HintFile.load_json(test._current_view, hints_file_name)
Exemple #3
0
 def test_unknown_key(self):
     """Asserts that HintFormatError is raised when given JSON
     has unknown key in hint
     """
     hints_file_name = 'test/hintfiles/unknown_keys_in_hint.hints'
     if not os.path.exists(hints_file_name):
         logging.error("Hint file %s not found", hints_file_name)
         return
     HintFile.load_json(test._current_view, hints_file_name)
Exemple #4
0
 def test_missing_text(self):
     """Asserts that HintFormatError is raised when given JSON
     doesn't have "text" key in hint
     """
     hints_file_name = 'test/hintfiles/no_text_in_hint.hints'
     if not os.path.exists(hints_file_name):
         logging.error("Hint file %s not found", hints_file_name)
         return
     HintFile.load_json(test._current_view, hints_file_name)
Exemple #5
0
 def test_illegal_places(self):
     """Asserts that HintFormatError is raised when given JSON
     has illegal value by "places" key in hint
     """
     hints_file_name = 'test/hintfiles/illegal_places_in_hint.hints'
     if not os.path.exists(hints_file_name):
         logging.error("Hint file %s not found", hints_file_name)
         return
     HintFile.load_json(test._current_view, hints_file_name)
Exemple #6
0
 def on_done(self, user_input):
     source_file_name = self.view.file_name()
     now = datetime.now()
     meta = Meta(created = now,
                 modified = now,
                 author = user_input,
                 createdWith = "SublimeHints editor v0.1",
                 createdTimestamp = datetime.fromtimestamp(os.path.getctime(source_file_name)),
                 modifiedTimestamp = datetime.fromtimestamp(os.path.getmtime(source_file_name)),
                 md5sum = hashlib.md5(open(source_file_name, 'rb').read()).hexdigest())
     hint_file = HintFile(meta, [], self.hints_file_name)
     hint_file.dump_json(self.view)
Exemple #7
0
 def test_correct_file(self):
     """Asserts that all supported key-value pairs are read correctly
     from correct JSON.
     This is implemented by comparison with predefined python dict_enum.
     Currently, following keys are asserted:
     * created
     * author
     """
     hints_file_name = 'test/hintfiles/correct.hints'
     if not os.path.exists(hints_file_name):
         logging.error("Hint file %s not found", hints_file_name)
         return
     hint_file = HintFile.load_json(test._current_view, hints_file_name)
     from hintfiles import correct_pydict
     for key in valid_meta_keys:
         try:
             value = getattr(hint_file.meta, key)
         except AttributeError:
             logging.exception("No key '%s' is found in file %s", key, hints_file_name)
             # ToDo: ?assertFail?
             assert False
         assert value == correct_pydict.filedata[key]