Example #1
0
def test_run_orphans():
    config = {
        "parser": "lookml-parser",
        "git": {
            "url": "https://github.com/exampleorg/examplerepo.git"
        },
        "infile_globs": ["test/test_orphans_repo/*.*.lkml"],
        "tmp_file": "test/parsed_lookml.json",
        "rules": {
            "other_rules": [{
                "name": "NoOrphansRule",
                "run": True
            }]
        },
        "output": {}
    }
    linter = LookMlLinter(config)
    file_out, field_out = linter.run()

    assert len(file_out) == 1
    assert len(field_out) == 0
    assert file_out[0] == {
        'file': 'test/test_orphans_repo/orphan.view.lkml',
        'passed': 0,
        'rule': 'NoOrphansRule'
    }
    if os.path.exists(config['tmp_file']):
        os.remove(config['tmp_file'])
Example #2
0
def test_run_orphans():
    config = {
        "git": {
            "url": "https://github.com/exampleorg/examplerepo.git"
        },
        "infile_globs": ["test/test_orphans_repo/*.*.lkml"],
        "rules": {
            "other_rules": [{
                "name": "NoOrphansRule",
                "run": True
            }]
        },
        "output": {},
    }
    linter = LookMlLinter(config)
    file_out, field_out = linter.run()

    assert len(file_out) == 1
    assert len(field_out) == 0
    assert file_out[0] == {
        "file": "test/test_orphans_repo/orphan.view.lkml",
        "passed": 0,
        "rule": "NoOrphansRule",
    }
Example #3
0
def test_run(monkeypatch):
    config = {
        "git": {
            "url": "https://github.com/exampleorg/examplerepo.git",
            "folder": "gitrepo",
        },
        "infile_globs": ["test/test_linter.view.lkml"],
        "rules": {
            "file_level_rules": [{
                "name": "FilenameViewnameMatchRule",
                "run": True
            }],
            "field_level_rules": [
                {
                    "name": "DescriptionRule",
                    "run": True
                },
                {
                    "name": "YesNoNameRule",
                    "run": True
                },
            ],
        },
        "output": {
            "csv": {
                "file_output": "test/linter_file_report.csv",
                "field_output": "test/linter_field_report.csv",
            },
            "simple_biquery": {
                "project_id": "some_project",
                "file_destination_table":
                "some_dataset.lookml_linter_file_report",
                "field_destination_table":
                "some_dataset.lookml_linter_field_rep",
            },
            "bigquery": {
                "target_bucket_name": "some_bucket",
                "bucket_folder": "some_folder",
                "gcs_project_id": "some_project",
                "project_id": "some_data_lake",
                "dataset": "some_dataset",
                "file_destination_table": "lookml_linter_file_report",
                "field_destination_table": "lookml_linter_field_report",
            },
        },
    }

    def do_nothing(*args,
                   **kwargs):  # destination_table, project_id, if_exists):
        pass

    monkeypatch.setattr(DataFrame, "to_gbq", do_nothing)
    monkeypatch.setattr(BqWriter, "upload", do_nothing)

    if os.path.exists(config["output"]["csv"]["file_output"]):
        os.remove(config["output"]["csv"]["file_output"])
    if os.path.exists(config["output"]["csv"]["field_output"]):
        os.remove(config["output"]["csv"]["field_output"])

    linter = LookMlLinter(config)
    linter.run()

    lines = open(config["output"]["csv"]["file_output"], "r").readlines()
    assert lines[0] == "time,file,rule,passed,repo,glob\n"
    # we are using in here as 1st col is current time and I decided it wasnt worth mocking for the test
    assert (
        "test_linter.view.lkml,FilenameViewnameMatchRule,0,https://github.com/exampleorg/examplerepo.git,test/test_linter.view.lkml\n"
        in lines[1])

    lines = open(config["output"]["csv"]["field_output"], "r").readlines()
    assert lines[0] == "time,file,rule,type,fieldname,passed,repo,glob\n"
    assert (
        "test_linter.view.lkml,DescriptionRule,dimension,city_code,1,https://github.com/exampleorg/examplerepo.git,test/test_linter.view.lkml\n"
        in lines[1])
    assert (
        "test_linter.view.lkml,DescriptionRule,dimension_group,current_week_start,0,https://github.com/exampleorg/examplerepo.git,test/test_linter.view.lkml\n"
        in lines[2])
    assert (
        "test_linter.view.lkml,DescriptionRule,measure,count,0,https://github.com/exampleorg/examplerepo.git,test/test_linter.view.lkml\n"
        in lines[3])

    if os.path.exists(config["output"]["csv"]["file_output"]):
        os.remove(config["output"]["csv"]["file_output"])
    if os.path.exists(config["output"]["csv"]["field_output"]):
        os.remove(config["output"]["csv"]["field_output"])