def test_random_graphite_metric(): "A time series of points where the time is randomly ordered" graphite_data = json.loads(""" [{ "target": "entries", "datapoints": [ [6.0, 1311836008], [1.0, 1311836012], [3.0, 1311836010], [2.0, 1311836011], [5.0, 1311836009] ] }] """) graph = {'graphite_data': graphite_data} full_long = wordgraph.describe(graph, source='graphite') expected = ''' This graph shows the relationship between time and metric. The x axis, time, ranges from 28 Jul 2011 06:53:28 to 28 Jul 2011 06:53:32. The y axis, metric, ranges from 1.0 to 6.0. It contains 1 series. The entries series is loosely linear ''' assertParagraph(full_long, expected)
def test_titled_graphite_documentation(): """Verify description of Graphite JSON response from Graphite docs for titled graph. Same as test_graphite_documentation, but graph has title. """ graphite_data = json.loads( """ [{ "target": "entries", "datapoints": [ [1.0, 1311836008], [2.0, 1311836009], [3.0, 1311836010], [5.0, 1311836011], [6.0, 1311836012] ] }] """ ) graph = {"title": "Metric Over Time", "graphite_data": graphite_data} full_long = wordgraph.describe(graph, source="graphite") expected = """ This graph, Metric Over Time, shows the relationship between time and metric. The x axis, time, ranges from 28 Jul 2011 06:53:28 to 28 Jul 2011 06:53:32. The y axis, metric, ranges from 1.0 to 6.0. It contains 1 series. The entries series is loosely linear """ assertParagraph(full_long, expected)
def test_time_goes_backwards(): """ A valid time series where time changes linearly backwards. Since it's a time series, we expect that we can sort it by time and present in order. This will not be true for arbitrary graphs. """ graphite_data = json.loads(""" [{ "target": "entries", "datapoints": [ [1.0, 1311836012], [2.0, 1311836011], [3.0, 1311836010], [5.0, 1311836009], [6.0, 1311836008] ] }] """) graph = {'graphite_data': graphite_data} full_long = wordgraph.describe(graph, source='graphite') expected = ''' This graph shows the relationship between time and metric. The x axis, time, ranges from 28 Jul 2011 06:53:28 to 28 Jul 2011 06:53:32. The y axis, metric, ranges from 1.0 to 6.0. It contains 1 series. The entries series is loosely linear ''' assertParagraph(full_long, expected)
def test_graphite_documentation(): """Verify description of Graphite JSON response from Graphite docs. The Graphite JSON response is for a single timeseries with five, monotonically increasing data points with the series name 'entries'. There is no graph title for the response. """ graphite_data = json.loads( """ [{ "target": "entries", "datapoints": [ [1.0, 1311836008], [2.0, 1311836009], [3.0, 1311836010], [5.0, 1311836011], [6.0, 1311836012] ] }] """ ) graph = {"graphite_data": graphite_data} full_long = wordgraph.describe(graph, source="graphite") expected = """ This graph shows the relationship between time and metric The x axis, time, ranges from 28 Jul 2011 06:53:28 to 28 Jul 2011 06:53:32 The y axis, metric, ranges from 1.0 to 6.0 It contains 1 series The entries series is loosely linear """ assertParagraph(full_long, expected)
def test_main_api(): """ Based on one of the integration tests... push some data through the main API methods to verify the public interfaces are basically solid """ graphite_data = json.loads(""" [{ "target": "entries", "datapoints": [ [1.0, 1311836008], [2.0, 1311836009], [3.0, 1311836010], [5.0, 1311836011], [6.0, 1311836012] ] }] """) graph = {'graphite_data': graphite_data} expected = """ This graph shows the relationship between time and metric The x axis, time, ranges from 28 Jul 2011 06:53:28 to 28 Jul 2011 06:53:32 The y axis, metric, ranges from 1.0 to 6.0 It contains 1 series The entries series is loosely linear """ full_long = wordgraph.describe(graph, source='graphite') assertParagraph(full_long, expected) english = wordgraph.Describer(source='graphite') result = english.description(graph) assertParagraph(result, expected)
def test_no_points(): """A time series no data points.""" graphite_data = json.loads(""" [{ "target": "entries", "datapoints": [] }] """) graph = {'graphite_data': graphite_data} full_long = wordgraph.describe(graph, source='graphite') expected = '''Graph invalid, because it contains no data points!''' assertParagraph(full_long, expected)
def test_memory_usage(): """Response data from Graphite server of fictional memory usage. Fictional data represents memory usage of a Graphite server. http://play.grafana.org/graphite/render?from=-15min&until=now&target=aliasByNode(integral(carbon.agents.ip-172-31-27-225-a.memUsage),3)&format=json """ with open("tests/data/memory_usage.json") as data: graph = {"graphite_data": json.load(data)} full_long = wordgraph.describe(graph, source="graphite") expected = """ This graph shows the relationship between time and metric The x axis, time, ranges from 04 Aug 2014 03:40:00 to 04 Aug 2014 03:54:00 The y axis, metric, ranges from 44736512.0 to 671047680.0 It contains 1 series """ assertParagraph(full_long, expected)
def test_single_point(): """A time series with a single data point.""" graphite_data = json.loads(""" [{ "target": "entries", "datapoints": [ [1.0, 1311836012] ] }] """) graph = {'graphite_data': graphite_data} full_long = wordgraph.describe(graph, source='graphite') expected = ''' This graph shows the relationship between time and metric. The entries series is a single point, with value 1.0 at time 28 Jul 2011 06:53:32. ''' assertParagraph(full_long, expected)
def test_titled_graphite_documentation(): """Verify description of Graphite JSON response from Graphite docs for titled graph. Same as test_graphite_documentation, but graph has title. """ graphite_data = json.loads(""" [{ "target": "entries", "datapoints": [ [1.0, 1311836008], [2.0, 1311836009], [3.0, 1311836010], [5.0, 1311836011], [6.0, 1311836012] ] }] """) graph = {'title': 'Metric Over Time', 'graphite_data': graphite_data} full_long = wordgraph.describe(graph, source='graphite') expected_sents = [ 'This graph, Metric Over Time, shows the relationship between time and metric', 'The x axis, time, ranges from 1311836008 to 1311836012', 'The y axis, metric, ranges from 1.0 to 6.0', 'It contains 1 series', 'The entries series is loosely linear', ] expected = ''' This graph, None, shows the relationship between time and metric. The x axis, time, ranges from 1311836008 to 1311836012. The y axis, metric, ranges from 1.0 to 6.0'. It contains 1 series'. The entriesseries is loosely linear' ''' assertParagraph(full_long, expected)
def test_two_points(): """A time series with two data points.""" graphite_data = json.loads(""" [{ "target": "entries", "datapoints": [ [1.0, 1311836012], [2.0, 1311836009] ] }] """) graph = {'graphite_data': graphite_data} full_long = wordgraph.describe(graph, source='graphite') expected = ''' This graph shows the relationship between time and metric. The x axis, time, ranges from 28 Jul 2011 06:53:29 to 28 Jul 2011 06:53:32. The y axis, metric, ranges from 1.0 to 2.0. It contains 1 series. The entries series is broadly linear ''' assertParagraph(full_long, expected)