1212# See the License for the specific language governing permissions and
1313# limitations under the License.
1414
15- import glob
1615import os
1716import shutil
1817import tempfile
1918import xml .etree .ElementTree as ET
19+ import yaml
2020from pathlib import Path
2121from synthtool .languages import java
2222import requests_mock
@@ -83,6 +83,13 @@ def assert_valid_xml(file):
8383 except ET .ParseError :
8484 pytest .fail (f"unable to parse XML: { file } " )
8585
86+ def assert_valid_yaml (file ):
87+ with open (file , "r" ) as stream :
88+ try :
89+ yaml .safe_load (stream )
90+ except yaml .YAMLError :
91+ pytest .fail (f"unable to parse YAML: { file } " )
92+
8693 with tempfile .TemporaryDirectory () as tempdir :
8794 workdir = shutil .copytree (
8895 FIXTURES / "java_templates" / "standard" , Path (tempdir ) / "standard"
@@ -95,8 +102,14 @@ def assert_valid_xml(file):
95102 java .common_templates (template_path = TEMPLATES_PATH )
96103 assert os .path .isfile ("README.md" )
97104
98- # ensure pom.xml files are valid XML
99- for file in glob .glob ("**/pom.xml" , recursive = True ):
100- assert_valid_xml (file )
105+ # lint xml, yaml files
106+ # use os.walk because glob ignores hidden directories
107+ for (dirpath , _ , filenames ) in os .walk (tempdir ):
108+ for file in filenames :
109+ (_ , ext ) = os .path .splitext (file )
110+ if ext == ".xml" :
111+ assert_valid_xml (os .path .join (dirpath , file ))
112+ elif ext == ".yaml" or ext == ".yml" :
113+ assert_valid_yaml (os .path .join (dirpath , file ))
101114 finally :
102115 os .chdir (cwd )
0 commit comments