File: test_paths.py

package info (click to toggle)
graphite-api 1.1.3-2%2Bdeb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 752 kB
  • sloc: python: 7,757; sh: 215; makefile: 150
file content (71 lines) | stat: -rw-r--r-- 2,137 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
from . import TestCase
from graphite_api.app import pathsFromTarget


class PathsTest(TestCase):
    """
    TestCase for pathsFromTarget function

    """
    def validate_paths(self, expected, test):
        """
        Assert the lengths of the expected list and the test list are the same
        Also assert that every member of the expected list is present in the
            test list.

        """
        # Check that test is a list
        self.assertTrue(isinstance(test, list))
        # Check length before converting to sets
        self.assertEqual(len(expected), len(test))
        # Convert lists to sets and verify equality
        self.assertEqual(set(expected), set(test))

    def test_simple(self):
        """
        Tests a target containing a single path expression.

        """
        target = 'test.simple.metric'
        expected = [target]
        self.validate_paths(expected, pathsFromTarget(target))

    def test_func_args(self):
        """
        Tests a target containing function call with path expressions as
        arguments.

        """
        path_1 = 'test.1.metric'
        path_2 = 'test.2.metric'
        target = 'sumSeries(%s,%s)' % (path_1, path_2)
        expected = [path_1, path_2]
        self.validate_paths(expected, pathsFromTarget(target))

    def test_func_kwargs(self):
        """
        Tests a target containing a function call with path expressions as
        a kwarg.

        """
        path_a = 'test.a.metric'
        path_b = 'test.b.metric'
        target = 'someFunc(%s,b=%s)' % (path_a, path_b)
        expected = [path_a, path_b]
        self.validate_paths(expected, pathsFromTarget(target))

    def test_func_nested(self):
        """
        Tests a target containing nested functions with a mix of args and
        kwargs.

        """
        paths = (
            'test.a.metric',
            'test.b.metric',
            'test.c.metric',
            'test.d.metric',
        )
        target = 'outerFunc(innerFunc(%s, %s), s=innerFunc(%s, %s))' % paths
        expected = list(paths)
        self.validate_paths(expected, pathsFromTarget(target))