Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def load(filename):
"""Helper method to load a LookML file from tests/resources and parse it."""
path = Path(__file__).parent / "resources" / filename
with path.open() as file:
return lkml.load(file)
def test_file(path: Path):
with path.open("r") as file:
text = file.read()
try:
parsed = lkml.load(text)
except Exception:
shutil.copy(path, github_path / "load_errors" / path.name)
logging.exception(f"Error parsing {path}")
try:
dumped = lkml.dump(parsed)
lkml.load(dumped)
except Exception:
with open(github_path / "dump_errors" / path.name, "w+") as file:
file.write(dumped)
logging.exception(f"Error serializing {path}")
def test_file(path: Path):
with path.open("r") as file:
text = file.read()
try:
parsed = lkml.load(text)
except Exception:
shutil.copy(path, github_path / "load_errors" / path.name)
logging.exception(f"Error parsing {path}")
try:
dumped = lkml.dump(parsed)
lkml.load(dumped)
except Exception:
with open(github_path / "dump_errors" / path.name, "w+") as file:
file.write(dumped)
logging.exception(f"Error serializing {path}")
raise IOError("Filename does not exist: %s" % infilepath)
self.infilepath = infilepath
if infilepath.endswith(".model.lkml"):
self.filetype = 'model'
elif infilepath.endswith(".view.lkml"):
self.filetype = 'view'
elif infilepath.endswith(".explore.lkml"):
self.filetype = 'explore'
else:
raise Exception("Unsupported filename " + infilepath)
self.base_filename = os.path.basename(infilepath)
self.base_name = self.base_filename.replace(".model.lkml", "").replace(".explore.lkml", "").replace(".view.lkml", "")
with open(infilepath, 'r') as file:
self.json_data = lkml.load(file)