Skip to content

Commit

Permalink
Add tests for document root detection
Browse files Browse the repository at this point in the history
  • Loading branch information
davelopez committed Jan 21, 2021
1 parent 20269d5 commit 32ad709
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions server/galaxyls/tests/unit/test_validation.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import pytest
from lxml import etree

from galaxyls.services.validation import DocumentValidator

from ...services.xsd.constants import TOOL_XSD_FILE
from ...services.xsd.validation import GalaxyToolValidationService
from .sample_data import (
Expand Down Expand Up @@ -62,3 +64,34 @@ def test_validate_macro_file_returns_diagnostics_when_syntax_error(self, xsd_sch
actual = service.validate_document(xml_document)

assert len(actual) == 1


class TestDocumentValidatorClass:
@pytest.mark.parametrize(
"source, expected",
[
("<tool>", True),
(" <tool>", True),
("\n<tool>", True),
("\n <tool>", True),
(" \n <tool>", True),
("unexpected <tool>", True),
(" unexpected <tool>", True),
("\nunexpected\n <tool>", True),
('<?xml version="1.0" encoding="UTF-8"?><tool>', True),
('<?xml version="1.0" encoding="UTF-8"?>\n<tool>', True),
("<macros>", True),
('<?xml version="1.0" encoding="UTF-8"?>\n<macros>', True),
("", False),
(" ", False),
("test", False),
("<test>", False),
],
)
def test_has_valid_root_returns_expected(self, source: str, expected: bool) -> None:
document = TestUtils.to_document(source)
validator = DocumentValidator()

actual = validator.has_valid_root(document)

assert actual == expected

0 comments on commit 32ad709

Please sign in to comment.