예제 #1
0
파일: test_reverse.py 프로젝트: acs/graal
    def test_analyze_error(self, check_output_mock):
        """Test whether an exception is thrown in case of errors"""

        check_output_mock.side_effect = subprocess.CalledProcessError(-1, "command", output=b'output')

        reverse = Reverse()
        kwargs = {
            'module_path': os.path.join(self.repo_path, "perceval"),
        }
        with self.assertRaises(GraalError):
            _ = reverse.analyze(**kwargs)
예제 #2
0
    def test_analyze(self):
        """Test whether Reverse returns the expected fields data"""

        reverse = Reverse()
        kwargs = {
            'module_path': os.path.join(self.repo_path, "perceval"),
        }
        result = reverse.analyze(**kwargs)

        self.assertIn('classes', result)
        self.assertTrue(type(result['classes']), dict)
        self.assertIn('nodes', result['classes'])
        self.assertTrue(type(result['classes']['nodes']), list)
        self.assertIn('links', result['classes'])
        self.assertTrue(type(result['classes']['links']), list)
        self.assertIn('packages', result)
        self.assertTrue(type(result['packages']), dict)
        self.assertTrue(type(result['packages']['nodes']), list)
        self.assertIn('links', result['packages'])
        self.assertTrue(type(result['packages']['links']), list)
예제 #3
0
class DependencyAnalyzer:
    """Class to obtain a graph representation of package and class dependencies information
    from a Python module. Such a representation can be then used to plot an UML diagram using common
    visualization libraries.
    """
    def __init__(self):
        self.reverse = Reverse()

    def analyze(self, module_path):
        """Analyze the content of a Python project using Pyreverse

        :param module_path: folder path

        :returns a dict containing the results of the analysis, like the one below
        {
          'image_path': ..
        }
        """
        kwargs = {'module_path': module_path}
        analysis = self.reverse.analyze(**kwargs)

        return analysis