Beispiel #1
0
def test_process_file5(config):
    grapher = LookMlGrapher(config)
    with pytest.raises(Exception) as e:
        lookml = LookML("test/empty.view.lkml")
        grapher.process_lookml(lookml)
    assert 'No models, views, or explores? test/empty.view.lkml' in str(
        e.value)
Beispiel #2
0
def test_process_file(config):
    grapher = LookMlGrapher(config)
    assert grapher.models_to_explores == []
    assert grapher.explores_to_views == []
    grapher.process_lookml(LookML("test/grapher_lkml/some_model.model.lkml"))
    assert grapher.models_to_explores == [('some_model', 'some_explore')]
    assert grapher.explores_to_views == [('some_explore', 'some_view'),
                                         ('some_explore', 'some_other_view')]
Beispiel #3
0
def test_process_file3(config):
    grapher = LookMlGrapher(config)
    assert grapher.node_map == {}
    lookml = LookML("test/grapher_lkml/some_view.view.lkml")
    grapher.process_lookml(lookml)

    assert 'some_view' in grapher.node_map
    assert grapher.node_map['some_view'] == NodeType.VIEW
Beispiel #4
0
def test_process_file4(config):
    grapher = LookMlGrapher(config)
    assert grapher.models_to_explores == []
    assert grapher.explores_to_views == []
    lookml = LookML("test/grapher_lkml/some_explore.explore.lkml")
    grapher.process_lookml(lookml)
    assert grapher.models_to_explores == []
    assert grapher.explores_to_views == [
        ("some_explore", "some_view"),
        ("some_explore", "some_other_view"),
    ]
Beispiel #5
0
class NoOrphansRule(Rule):
    """
        Look for views unreferenced by any explores
    """
    def __init__(self, config):
        """Initialize the rule

        Args:
            config (JSON): configuration

        """
        self.config = config
        self.grapher = LookMlGrapher(config)
        self.view_dict = {}

    def run(self, json_data):
        """run the rule

        Args:
            json_data (JSON): json_data of the lkml-parsed JSON dictionary for this file

        Returns:
            (tuple): tuple containing:

                relevant (bool): is this rule relevant for this JSON chunk?

                passed (bool): did the rule pass?

        """
        pass  # pragma: no cover

    def process_lookml(self, lookml):
        """process the JSON_DATA of a file, delegating down to the grapher
            also store metadata we'll need in a later stage

        Args:
            lookmlk (LookML): instance of LookML

        Returns:
            nothing. side effect is to store data in grapher and in this class

        """
        self.grapher.process_lookml(lookml)
        # we'll need the view_namme->filename mapping to output later
        if lookml.has_views():
            v = lookml.views()[0]
            view_name = lookml.base_name
            filepath = lookml.infilepath
            self.view_dict[view_name] = filepath

    def finish_up(self, file_out):
        """find the orphans, if any, and add results to file_out

        Args:
            file_out (list): list of results for files

        Returns:
            file_out (list)

        """
        self.grapher.tag_orphans()
        orphans = self.grapher.orphans()
        for orphan in orphans:
            simple_filepath = self.view_dict[orphan]
            logging.info("Found orphan %s in %s", orphan, simple_filepath)
            out = {"file": simple_filepath, "rule": self.name(), "passed": 0}
            file_out.append(out)
        return file_out