Ejemplo n.º 1
0
 def test_draw_default_rows(self, width_patched, sys_patched):
     sys_patched.stdout = StringIO()
     plot = Plot()
     plot.draw(DEFAULT_ROWS_FIXTURE[0])
     sys_patched.stdout.seek(0)
     output = sys_patched.stdout.read()
     assert output == DEFAULT_ROWS_FIXTURE[1]
Ejemplo n.º 2
0
 def test_draw_default_rows(self, width_patched, sys_patched):
     sys_patched.stdout = StringIO()
     plot = Plot()
     plot.draw(DEFAULT_ROWS_FIXTURE[0])
     sys_patched.stdout.seek(0)
     output = sys_patched.stdout.read()
     assert output == DEFAULT_ROWS_FIXTURE[1]
Ejemplo n.º 3
0
 def test_draw_maxx(self, width_patched, sys_patched):
     width_patched.return_value = 10
     sys_patched.stdout = StringIO()
     plot = Plot(max_x=100)
     plot.draw(MAXX_ROWS_FIXTURE[0])
     sys_patched.stdout.seek(0)
     output = sys_patched.stdout.read()
     assert sys_patched.stdout.read() == MAXX_ROWS_FIXTURE[1]
Ejemplo n.º 4
0
 def test_draw_five_rows(self, width_patched, sys_patched):
     width_patched.return_value = 10
     sys_patched.stdout = StringIO()
     plot = Plot(rows=5)
     plot.draw(FIVE_ROWS_FIXTURE[0])
     sys_patched.stdout.seek(0)
     output = sys_patched.stdout.read()
     assert output == FIVE_ROWS_FIXTURE[1]
Ejemplo n.º 5
0
 def test_draw_maxx(self, width_patched, sys_patched):
     width_patched.return_value = 10
     sys_patched.stdout = StringIO()
     plot = Plot(max_x=100)
     plot.draw(MAXX_ROWS_FIXTURE[0])
     sys_patched.stdout.seek(0)
     output = sys_patched.stdout.read()
     assert sys_patched.stdout.read() == MAXX_ROWS_FIXTURE[1]
Ejemplo n.º 6
0
 def test_draw_five_rows(self, width_patched, sys_patched):
     width_patched.return_value = 10
     sys_patched.stdout = StringIO()
     plot = Plot(rows=5)
     plot.draw(FIVE_ROWS_FIXTURE[0])
     sys_patched.stdout.seek(0)
     output = sys_patched.stdout.read()
     assert output == FIVE_ROWS_FIXTURE[1]
Ejemplo n.º 7
0
                                for k in filter(lambda k: getattr(suboptions, str(k)),
                                datasource_cls.METRIC_QUERY_CLS.optional_keys())})

            try:
                query = datasource_cls.METRIC_QUERY_CLS(**query_params)
            except InvalidMetricQuery, e:
                raise InvalidParams(e.errors)

            try:
                datasource = datasource_cls(config)
            except InvalidDataSourceConfig, e:
                print("Datasource config invalid {}".format(e.errors), file=sys.stderr)
            else:
                plot = Plot(max_x=suboptions.plot_maxx)
                while True:
                    plot.draw(datasource.datapoints(query, maxdatapoints=plot.width()))
                    if not suboptions.refresh:
                        break
                    try:
                        sleep(int(suboptions.refresh_freq))
                    except KeyboardInterrupt:
                        break

        @staticmethod
        def options():
            # Command Options
            command_options = [
                (("--refresh",), {"action": "store_true", "default": False,
                                  "help": "Keep graphing forever, default False "}),
                (("--refresh-freq",), {"action": "store", "type": "int", "default": 10,
                                       "help": "Refresh frequency in seconds, default 10s"}),
Ejemplo n.º 8
0
            try:
                query = datasource_cls.METRIC_QUERY_CLS(**query_params)
            except InvalidMetricQuery, e:
                raise InvalidParams(e.errors)

            try:
                datasource = datasource_cls(config)
            except InvalidDataSourceConfig, e:
                print("Datasource config invalid {}".format(e.errors),
                      file=sys.stderr)
            else:
                plot = Plot(max_x=suboptions.plot_maxx)
                while True:
                    plot.draw(
                        datasource.datapoints(query,
                                              maxdatapoints=plot.width()))
                    if not suboptions.refresh:
                        break
                    try:
                        sleep(int(suboptions.refresh_freq))
                    except KeyboardInterrupt:
                        break

        @staticmethod
        def options():
            # Command Options
            command_options = [
                (("--refresh", ), {
                    "action": "store_true",
                    "default": False,