Skip to content

Commit

Permalink
Apply lint
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Stein <steinlink@gmail.com>
  • Loading branch information
No Author authored and texodus committed Aug 4, 2024
1 parent e7d92ab commit ca5cc0d
Show file tree
Hide file tree
Showing 18 changed files with 52 additions and 326 deletions.
4 changes: 2 additions & 2 deletions docs/docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,8 @@ pnpm run test

The JavaScript test suite is composed of two sections: a Node.js test, which
asserts behavior of the `@finos/perspective` library, and a suite of
[Playwright](https://playwright.dev/) tests, which
assert the behavior of the rest of the UI facing packages.
[Playwright](https://playwright.dev/) tests, which assert the behavior of the
rest of the UI facing packages.

```bash
pnpm run test --update-snapshots
Expand Down
2 changes: 0 additions & 2 deletions rust/perspective-python/bench/tornado/server/new_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,11 @@
# ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛

import multiprocessing
import asyncio
import os
import os.path
import time
from perspective.core.globalpsp import shared_client
from perspective.handlers.tornado import PerspectiveTornadoHandler
from tornado.websocket import websocket_connect
import tornado
import threading
import numpy
Expand Down
1 change: 1 addition & 0 deletions rust/perspective-python/perspective/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"PerspectiveWidget",
"PerspectiveViewer",
"PerspectiveTornadoHandler",
"ProxySession",
"Table",
"View",
]
Expand Down
6 changes: 3 additions & 3 deletions rust/perspective-python/perspective/handlers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@
# ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛

try:
from .aiohttp import PerspectiveAIOHTTPHandler
from .aiohttp import PerspectiveAIOHTTPHandler # noqa: F401
except ImportError:
...

try:
from .starlette import PerspectiveStarletteHandler
from .starlette import PerspectiveStarletteHandler # noqa: F401
except ImportError:
...

try:
from .tornado import PerspectiveTornadoHandler
from .tornado import PerspectiveTornadoHandler # noqa: F401
except ImportError:
...
44 changes: 24 additions & 20 deletions rust/perspective-python/perspective/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,35 @@
from faker import Faker


fake = Faker()

# Our tests construct naive datetimes everywhere
# so setting it here is an easy way to fix it globally.
import os

# Perspective used to support datetime.date and datetime.datetime
# as Table() constructor arguments, but now we forward the parameters
# directly to JSON.loads. So to make sure the tests dont need to be
# so utterly transmogrified, we have this little hack :)
import json


os.environ["TZ"] = "UTC"


def new_encoder(self, obj):
if isinstance(obj, datetime):
return str(obj)
elif isinstance(obj, date):
return str(obj)
else:
return old(self, obj)


old = json.JSONEncoder.default
json.JSONEncoder.default = new_encoder

fake = Faker()


def _make_date_time_index(size, time_unit):
return pd.date_range("2000-01-01", periods=size, freq=time_unit)

Expand Down Expand Up @@ -248,21 +270,3 @@ def superstore(count=100):
dat["Profit"] = round(random() * 1000, 2)
data.append(dat)
return pd.DataFrame(data)


# Perspective used to support datetime.date and datetime.datetime
# as Table() constructor arguments, but now we forward the parameters
# directly to JSON.loads. So to make sure the tests dont need to be
# so utterly transmogrified, we have this little hack :)
import json
old = json.JSONEncoder.default

def new_encoder(self, obj):
if isinstance(obj, datetime):
return str(obj)
elif isinstance(obj, date):
return str(obj)
else:
return old(self, obj)

json.JSONEncoder.default = new_encoder
25 changes: 1 addition & 24 deletions rust/perspective-python/perspective/tests/core/test_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
Server,
Client,
)
from pytest import mark, raises
from pytest import mark


def syncify(f):
Expand Down Expand Up @@ -119,29 +119,6 @@ def _task():
assert _task() == 10
tbl.delete()

@mark.skip(reason="We take a loop to construct the client now")
def test_async_call_loop_error_if_no_loop(self):
server = Server()
client = Client.from_server(
server, lambda fn, *args: TestAsync.loop.add_callback(fn, *args)
)
tbl = client.table({"a": "integer", "b": "float", "c": "string"})

with raises(PerspectiveError):
# loop not set - errors
tbl.update(data)

tbl.update(data)

@syncify
def _task():
return tbl.size()

# subsequent calls to call_loop will work if loop_callback is set.
assert _task() == 10

tbl.delete()

def test_async_multiple_managers_queue_process(self):
server = Server()
client = Client.from_server(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def validate_post(self, msg, expected=None):
def test_server_host_table(self):
server = Server()
client = Client.from_server(server)
table = client.table(data, name="table1")
client.table(data, name="table1")
table2 = client.open_table("table1")
assert table2.schema() == {"a": "integer", "b": "string"}

Expand Down Expand Up @@ -126,15 +126,11 @@ def test_locked_client_create_view(self):
assert client._get_view("view1").schema() == {"a": "integer", "b": "string"}

def test_server_create_view_zero(self):
message = {"id": 1, "table_name": "table1", "view_name": "view1", "cmd": "view"}
server = Server()
client = Client.from_server(server)
client.table(data, name="table1")
table = client.open_table("table1")
print(f"XXX: {dir(table)}")
assert table.view().dimensions()["num_view_rows"] == 3
# client._process(message, self.post)
# assert client._views["view1"].num_rows() == 3

def test_server_create_view_one(self):
server = Server()
Expand Down
10 changes: 6 additions & 4 deletions rust/perspective-python/perspective/tests/table/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@
# ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃
# ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛

import sys
from datetime import date, datetime, timezone
from datetime import date, datetime
import perspective
from pytest import mark, raises, skip
from pytest import mark, raises
import pytest
import perspective as psp

Expand Down Expand Up @@ -446,7 +445,10 @@ def test_table_index_date_with_none(self):
},
index="a",
)
ts = lambda x: int(datetime.timestamp(x) * 1000)

def ts(x):
return int(datetime.timestamp(x) * 1000)

assert tbl.view().to_columns() == {
"a": [
None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def test_table_datetime_min_epoch(self, util):
def test_table_datetime_cant_convert_from_int(self):
data = pd.DataFrame({"a": [0]})
table = Table({"a": "datetime"})
with raises(PerspectiveError) as ex:
with raises(PerspectiveError):
table.update(data)
# assert str(ex.value) == "..."

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def test_table_bool_infer_str_all_formats_from_schema(self):
"b": [False, False, False, False, False],
}

def test_table_infer_bool(self):
def test_table_infer_bool_variant(self):
data = {"a": [None, None, None, None, True, True, True]}
tbl = Table(data)
assert tbl.schema() == {"a": "boolean"}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
# ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃
# ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛

from datetime import date, datetime
from pytest import mark
import perspective as psp

client = psp.Server().new_local_client()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@ def test_to_arrow_date_symmetric(self):
assert tbl.schema() == {"a": "date"}
arr = tbl.view().to_arrow()
tbl2 = Table(arr)
ts = lambda x: int(datetime.timestamp(x) * 1000)

def ts(x):
return int(datetime.timestamp(x) * 1000)

assert tbl2.schema() == tbl.schema()
assert tbl2.view().to_columns() == {
"a": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
# ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃
# ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛

import os
import perspective as psp

client = psp.Server().new_local_client()
Expand Down
Loading

0 comments on commit ca5cc0d

Please sign in to comment.