Esempio n. 1
0
  def validate(self):
    """Validate one tag definition file.

    Raises:
      TagDefinitionError if
        - the file cannot be parses as YAML.
        - the file contains duplicate keys.
        - the file contains non-string values.
        - the top-level keys are unequal to REQUIRED_TOP_LEVEL_KEYS.
        - an item does not at least specify the keys id, display_name.
        - an item contains a key that is not in SUPPORTED_ITEM_LEVEL_KEYS.
    """
    file_content = filesystem_utils.get_content(self._file_path)
    self.parse_yaml_file(file_content)
Esempio n. 2
0
  def validate(self, file_path: str, do_smoke_test: bool):
    """Validate one documentation markdown file."""
    self._file_path = file_path
    raw_content = filesystem_utils.get_content(self._file_path)
    self._lines = raw_content.split("\n")
    first_line = self._lines[0].replace("‌", "")
    self.policy = self.get_policy_from_first_line(first_line)

    try:
      self.policy.assert_correct_file_path(self._file_path,
                                           self._documentation_dir)
      # Populate _parsed_description with the description
      self.consume_description()
      # Populate _parsed_metadata with the metadata tag mapping
      self.consume_metadata()
      self.policy.assert_correct_metadata(self._parsed_metadata)
    except MarkdownDocumentationError as e:
      self.raise_error(str(e))
    self.assert_allowed_license()
    self.assert_publisher_page_exists()
    if do_smoke_test:
      self.smoke_test_asset()
Esempio n. 3
0
 def test_get_content_populated_file(self):
   content = "# Module"
   temp_file = self.create_tempfile(content=content)
   self.assertEqual(content, filesystem_utils.get_content(temp_file))
Esempio n. 4
0
 def test_get_content_empty_file(self):
   temp_file = self.create_tempfile()
   self.assertEmpty(filesystem_utils.get_content(temp_file))