예제 #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]
예제 #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]
예제 #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]
예제 #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]
예제 #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]
예제 #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]
예제 #7
0
            # set also the optional keys given as suboptional params
            query_params.update(**{str(k): getattr(suboptions, str(k))
                                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 "}),
예제 #8
0
                        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 = [