Esempio n. 1
0
 def create_random_heatmap_grid(self, width, height, steps):
     zmax = []
     columns = [
         Column(np.linspace(0, width, width), 'x'),
         Column(np.linspace(0, height, height), 'y')
     ]
     for k in range(steps):
         z = [[self.create_heatmap_entry() for x in range(0, width)]
              for y in range(0, height)]
         columns.append(Column(z, 'z{}'.format(k + 1)))
         zmax.append(np.max(z))
     return Grid(columns), zmax
Esempio n. 2
0
def test_column_json_encoding():
    columns = [
        Column(numeric_list, 'col 1'),
        Column(mixed_list, 'col 2'),
        Column(np_list, 'col 3')
    ]
    json_columns = _json.dumps(columns,
                               cls=_plotly_utils.utils.PlotlyJSONEncoder,
                               sort_keys=True)
    assert ('[{"data": [1, 2, 3], "name": "col 1"}, '
            '{"data": [1, "A", "2014-01-05", '
            '"2014-01-05 01:01:01", '
            '"2014-01-05 01:01:01.000001"], '
            '"name": "col 2"}, '
            '{"data": [1, 2, 3, null, null, null, '
            '"2014-01-05"], "name": "col 3"}]' == json_columns)
Esempio n. 3
0
    def create_simulation_grid(self, grid_simulation):
        zmax = []

        steps = len(grid_simulation)
        width = len(grid_simulation[0])
        height = len(grid_simulation[0][0])

        columns = [
            Column(np.linspace(0, width, width), 'x'),
            Column(np.linspace(0, height, height), 'y')
        ]
        for k in range(steps):
            z = [[grid_simulation[k][x][y] for x in range(0, width)]
                 for y in range(0, height)]
            columns.append(Column(z, 'z{}'.format(k + 1)))
            zmax.append(np.max(z))
        return Grid(columns), zmax
Esempio n. 4
0
    def test_upload_meta_with_grid(self):
        c1 = Column([1, 2, 3, 4], "first column")
        Grid([c1])

        unique_filename = self.random_filename()

        py.grid_ops.upload(
            self._grid, unique_filename, meta=self._meta, auto_open=False
        )
Esempio n. 5
0
    def test_duplicate_filenames(self):
        c1 = Column([1, 2, 3, 4], "first column")
        g = Grid([c1])

        random_chars = [
            random.choice(string.ascii_uppercase) for _ in range(5)
        ]
        unique_filename = "Valid Grid " + "".join(random_chars)
        py.grid_ops.upload(g, unique_filename, auto_open=False)
        try:
            py.grid_ops.upload(g, unique_filename, auto_open=False)
        except PlotlyRequestError as e:
            pass
        else:
            self.fail("Expected this to fail!")
Esempio n. 6
0
class MetaTest(PlotlyTestCase):

    _grid = grid = Grid([Column([1, 2, 3, 4], 'first column')])
    _meta = {"settings": {"scope1": {"model": "Unicorn Finder", "voltage": 4}}}

    def setUp(self):
        super(MetaTest, self).setUp()
        py.sign_in('PythonTest', 'xnyU0DEwvAQQCwHVseIL')

    def random_filename(self):
        random_chars = [
            random.choice(string.ascii_uppercase) for _ in range(5)
        ]
        unique_filename = 'Valid Grid with Meta ' + ''.join(random_chars)
        return unique_filename

    @attr('slow')
    def test_upload_meta(self):
        unique_filename = self.random_filename()
        grid_url = py.grid_ops.upload(self._grid,
                                      unique_filename,
                                      auto_open=False)

        # Add some Metadata to that grid
        py.meta_ops.upload(self._meta, grid_url=grid_url)

    @attr('slow')
    def test_upload_meta_with_grid(self):
        c1 = Column([1, 2, 3, 4], 'first column')
        Grid([c1])

        unique_filename = self.random_filename()

        py.grid_ops.upload(self._grid,
                           unique_filename,
                           meta=self._meta,
                           auto_open=False)

    @skip('adding this for now so test_file_tools pass, more info' +
          'https://github.com/plotly/python-api/issues/263')
    def test_metadata_to_nonexistent_grid(self):
        non_exist_meta_url = 'https://local.plot.ly/~GridTest/999999999'
        with self.assertRaises(PlotlyRequestError):
            py.meta_ops.upload(self._meta, grid_url=non_exist_meta_url)
Esempio n. 7
0
 def test_column_append(self):
     g = self.upload_and_return_grid()
     new_col = Column([1, 5, 3], "new col")
     py.grid_ops.append_columns([new_col], grid=g)
Esempio n. 8
0
 def get_grid(self):
     c1 = Column([1, 2, 3, 4], "first column")
     c2 = Column(["a", "b", "c", "d"], "second column")
     g = Grid([c1, c2])
     return g
Esempio n. 9
0
 def test_duplicate_columns(self):
     c1 = Column([1, 2, 3, 4], "first column")
     c2 = Column(["a", "b", "c", "d"], "first column")
     with self.assertRaises(InputError):
         Grid([c1, c2])
Esempio n. 10
0
 def test_row_append_of_non_uploaded_grid(self):
     c1 = Column([1, 2, 3, 4], "first column")
     rows = [[1], [2]]
     g = Grid([c1])
     with self.assertRaises(PlotlyError):
         py.grid_ops.append_rows(rows, grid=g)
Esempio n. 11
0
 def test_column_append_of_non_uploaded_grid(self):
     c1 = Column([1, 2, 3, 4], "first column")
     c2 = Column(["a", "b", "c", "d"], "second column")
     g = Grid([c1])
     with self.assertRaises(PlotlyError):
         py.grid_ops.append_columns([c2], grid=g)
Esempio n. 12
0
 def get_grid(self):
     c1 = Column([1, 2, 3, 4], 'first column')
     c2 = Column(['a', 'b', 'c', 'd'], 'second column')
     g = Grid([c1, c2])
     return g
Esempio n. 13
0
 def test_duplicate_columns(self):
     c1 = Column([1, 2, 3, 4], 'first column')
     c2 = Column(['a', 'b', 'c', 'd'], 'first column')
     with self.assertRaises(InputError):
         Grid([c1, c2])
Esempio n. 14
0
 def test_column_append_of_non_uploaded_grid(self):
     c1 = Column([1, 2, 3, 4], 'first column')
     c2 = Column(['a', 'b', 'c', 'd'], 'second column')
     g = Grid([c1])
     with self.assertRaises(PlotlyError):
         py.grid_ops.append_columns([c2], grid=g)