Пример #1
0
def test_orphans(config):
    grapher = LookMlGrapher(config)
    grapher.node_map['model_a'] = NodeType.MODEL
    grapher.node_map['explore_a'] = NodeType.EXPLORE
    grapher.node_map['view_a'] = NodeType.VIEW
    grapher.node_map['orphan'] = NodeType.VIEW
    grapher.models_to_explores.append(('model_a', 'explore_a'))
    grapher.explores_to_views.append(('explore_a', 'view_a'))
    grapher.tag_orphans()
    orphans = grapher.orphans()
    assert len(orphans) == 1
    assert list(orphans)[0] == 'orphan'
Пример #2
0
def test_orphans(config):
    grapher = LookMlGrapher(config)
    grapher.node_map["model_a"] = NodeType.MODEL
    grapher.node_map["explore_a"] = NodeType.EXPLORE
    grapher.node_map["view_a"] = NodeType.VIEW
    grapher.node_map["orphan"] = NodeType.VIEW
    grapher.models_to_explores.append(("model_a", "explore_a"))
    grapher.explores_to_views.append(("explore_a", "view_a"))
    grapher.tag_orphans()
    orphans = grapher.orphans()
    assert len(orphans) == 1
    assert list(orphans)[0] == "orphan"
Пример #3
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
Пример #4
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 lookml-parser 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_file(self, json_data):
        '''process the JSON_DATA of a file, delegating down to the grapher
            also store metadata we'll need in a later stage

        Args:
            json_data (JSON): json_data: parsed lkml file as JSON

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

        '''
        self.grapher.process_file(filepath=None, json_data=json_data)
        # we'll need the view_namme->filename mapping to output later
        if 'views' in json_data['files'][0]:
            view_name = json_data['files'][0]['views'][0]['_view']
            filepath = json_data['files'][0]['_file_path']
            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] #['files'][0]['_file_path']
            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)