def test_markdown_with_allowed_license(self): filesystem = MockFilesystem() filesystem.set_contents("root/google/models/model/1.md", MINIMAL_MARKDOWN_WITH_ALLOWED_LICENSE) self.set_up_publisher_page(filesystem, "google") validator.validate_documentation_files(documentation_dir="root", filesystem=filesystem)
def test_minimal_markdown_parsed_placeholder(self): filesystem = MockFilesystem() filesystem.set_contents("root/google/models/text-embedding-model/1.md", MINIMAL_MARKDOWN_PLACEHOLDER_TEMPLATE) self.set_up_publisher_page(filesystem, "google") validator.validate_documentation_files(documentation_dir="root", filesystem=filesystem)
def test_minimal_markdown_parsed_saved_model(self): filesystem = MockFilesystem() filesystem.set_contents("root/google/models/text-embedding-model/1.md", self.minimal_markdown) self.set_up_publisher_page(filesystem, "google") validator.validate_documentation_files(documentation_dir="root", filesystem=filesystem)
def test_invalid_markdown_fails(self): filesystem = MockFilesystem() filesystem.set_contents("root/publisher/model/1.md", "INVALID MARKDOWN") with self.assertRaisesRegexp(validator.MarkdownDocumentationError, ".*First line.*"): validator.validate_documentation_files(documentation_dir="root", filesystem=filesystem)
def test_minimal_collection_markdown_parsed(self): filesystem = MockFilesystem() filesystem.set_contents( "root/google/collections/text-embedding-collection/1.md", MINIMAL_COLLECTION_MARKDOWN) self.set_up_publisher_page(filesystem, "google") validator.validate_documentation_files(documentation_dir="root", filesystem=filesystem)
def test_minimal_markdown_parsed_coral(self): filesystem = MockFilesystem() filesystem.set_contents( "root/google/models/text-embedding-model/1.md", (MINIMAL_MARKDOWN_CORAL_TEMPLATE % self.model_path)) self.set_up_publisher_page(filesystem, "google") validator.validate_documentation_files(documentation_dir="root", filesystem=filesystem)
def test_minimal_markdown_not_in_publisher_dir(self): filesystem = MockFilesystem() filesystem.set_contents("root/gooogle/models/wrong-location/1.md", self.minimal_markdown) with self.assertRaisesRegexp(validator.MarkdownDocumentationError, ".*placed in the publisher directory.*"): validator.validate_documentation_files(documentation_dir="root", filesystem=filesystem)
def test_minimal_markdown_does_not_end_with_md_fails(self): filesystem = MockFilesystem() filesystem.set_contents("root/google/models/wrong-extension/1.mdz", self.minimal_markdown) with self.assertRaisesRegexp(validator.MarkdownDocumentationError, r".*end with \"\.md.\"*"): validator.validate_documentation_files(documentation_dir="root", filesystem=filesystem)
def test_markdown_with_duplicate_metadata(self): filesystem = MockFilesystem() filesystem.set_contents("root/google/models/text-embedding-model/1.md", MARKDOWN_WITH_DUPLICATE_METADATA) with self.assertRaisesRegexp(validator.MarkdownDocumentationError, ".*duplicate.*asset-path.*"): validator.validate_documentation_files(documentation_dir="root", filesystem=filesystem)
def test_markdown_with_unexpected_lines(self): filesystem = MockFilesystem() filesystem.set_contents("root/google/models/text-embedding-model/1.md", MARKDOWN_WITH_UNEXPECTED_LINES) with self.assertRaisesRegexp(validator.MarkdownDocumentationError, ".*Unexpected line.*"): validator.validate_documentation_files(documentation_dir="root", filesystem=filesystem)
def test_markdown_without_description(self): filesystem = MockFilesystem() filesystem.set_contents("root/google/models/text-embedding-model/1.md", MARKDOWN_WITHOUT_DESCRIPTION) with self.assertRaisesRegexp(validator.MarkdownDocumentationError, ".*has to contain a short description.*"): validator.validate_documentation_files(documentation_dir="root", filesystem=filesystem)
def test_markdown_with_missing_metadata(self): filesystem = MockFilesystem() filesystem.set_contents("root/google/models/text-embedding-model/1.md", MARKDOWN_WITH_MISSING_METADATA) with self.assertRaisesRegexp(validator.MarkdownDocumentationError, ".*missing.*fine-tunable.*module-type.*"): validator.validate_documentation_files(documentation_dir="root", filesystem=filesystem)
def test_publisher_markdown_at_incorrect_location_fails(self): filesystem = MockFilesystem() filesystem.set_contents("root/google/publisher.md", MINIMAL_PUBLISHER_MARKDOWN % "some-publisher") with self.assertRaisesRegexp(validator.MarkdownDocumentationError, r".*some-publisher\.md.*"): validator.validate_documentation_files(documentation_dir="root", filesystem=filesystem)
def test_markdown_with_bad_module_type(self): filesystem = MockFilesystem() filesystem.set_contents("root/google/models/model/1.md", MINIMAL_MARKDOWN_WITH_BAD_MODULE_TYPE) self.set_up_publisher_page(filesystem, "google") with self.assertRaisesRegexp(validator.MarkdownDocumentationError, ".*metadata has to start with.*"): validator.validate_documentation_files(documentation_dir="root", filesystem=filesystem)
def test_markdown_with_unknown_license(self): filesystem = MockFilesystem() filesystem.set_contents("root/google/models/model/1.md", MINIMAL_MARKDOWN_WITH_UNKNOWN_LICENSE) self.set_up_publisher_page(filesystem, "google") with self.assertRaisesRegexp(validator.MarkdownDocumentationError, ".*specify a license id from list.*"): validator.validate_documentation_files(documentation_dir="root", filesystem=filesystem)
def test_fails_if_publisher_page_does_not_exist(self): filesystem = MockFilesystem() filesystem.set_contents( "root/publisher-without-page/models/text-embedding-model/1.md", MINIMAL_MARKDOWN_WITH_UNKNOWN_PUBLISHER) with self.assertRaisesRegexp(validator.MarkdownDocumentationError, ".*Publisher documentation does not.*"): validator.validate_documentation_files(documentation_dir="root", filesystem=filesystem)
def test_bad_model_does_not_pass_smoke_test(self): filesystem = MockFilesystem() filesystem.set_contents("root/google/models/text-embedding-model/1.md", self.minimal_markdown_with_bad_model) self.set_up_publisher_page(filesystem, "google") with self.assertRaisesRegexp(validator.MarkdownDocumentationError, ".*failed to parse.*"): validator.validate_documentation_files( documentation_dir="root", files_to_validate=["google/models/text-embedding-model/1.md"], filesystem=filesystem)
def test_markdown_with_bad_handle(self): for markdown in [ MARKDOWN_WITH_DOUBLE_SLASH_IN_HANDLE, MARKDOWN_WITH_BAD_CHARS_IN_HANDLE, MARKDOWN_WITH_MISSING_MODEL_IN_HANDLE ]: filesystem = MockFilesystem() filesystem.set_contents("root/google/models/model/1.md", markdown) with self.assertRaisesRegexp(validator.MarkdownDocumentationError, ".*First line of the documentation*"): validator.validate_documentation_files( documentation_dir="root", filesystem=filesystem)
def test_model_with_invalid_filenames_fails_smoke_test(self): filesystem = MockFilesystem() filesystem.set_contents("root/google/models/text-embedding-model/1.md", self.minimal_markdown) self.set_up_publisher_page(filesystem, "google") with open(os.path.join(self.model_path, ".invalid_file"), "w") as bad_file: bad_file.write("This file shouldn't be here") documentation_parser = validator.DocumentationParser( "root", filesystem) with self.assertRaisesRegexp(validator.MarkdownDocumentationError, r"Invalid filepath.*\.invalid_file"): validator.validate_documentation_files( documentation_parser.validate( file_path="root/google/models/text-embedding-model/1.md", do_smoke_test=True))
def test_minimal_markdown_parsed_with_selected_files(self): filesystem = MockFilesystem() filesystem.set_contents("root/google/models/text-embedding-model/1.md", self.minimal_markdown) self.set_up_publisher_page(filesystem, "google") num_validated = validator.validate_documentation_files( documentation_dir="root", files_to_validate=["google/models/text-embedding-model/1.md"], filesystem=filesystem) self.assertEqual(1, num_validated)
def test_publisher_markdown_at_correct_location(self): filesystem = MockFilesystem() self.set_up_publisher_page(filesystem, "some-publisher") validator.validate_documentation_files(documentation_dir="root", filesystem=filesystem)
def test_minimal_publisher_markdown_parsed(self): filesystem = MockFilesystem() self.set_up_publisher_page(filesystem, "some-publisher") validator.validate_documentation_files(documentation_dir="root", filesystem=filesystem)