Added test for db.mtime_ns

This commit is contained in:
Simon Willison 2020-05-30 11:17:20 -07:00
commit 4d798ca0e3
2 changed files with 14 additions and 2 deletions

View file

@ -33,7 +33,7 @@ class Database:
self.cached_table_counts = None self.cached_table_counts = None
self._write_thread = None self._write_thread = None
self._write_queue = None self._write_queue = None
if not self.is_mutable: if not self.is_mutable and not self.is_memory:
p = Path(path) p = Path(path)
self.hash = inspect_hash(p) self.hash = inspect_hash(p)
self.cached_size = p.stat().st_size self.cached_size = p.stat().st_size
@ -197,6 +197,8 @@ class Database:
@property @property
def mtime_ns(self): def mtime_ns(self):
if self.is_memory:
return None
return Path(self.path).stat().st_mtime_ns return Path(self.path).stat().st_mtime_ns
@property @property

View file

@ -1,7 +1,7 @@
""" """
Tests for the datasette.database.Database class Tests for the datasette.database.Database class
""" """
from datasette.database import Results, MultipleValues from datasette.database import Database, Results, MultipleValues
from datasette.utils import sqlite3 from datasette.utils import sqlite3
from .fixtures import app_client from .fixtures import app_client
import pytest import pytest
@ -188,3 +188,13 @@ async def test_execute_write_fn_exception(db):
with pytest.raises(AssertionError): with pytest.raises(AssertionError):
await db.execute_write_fn(write_fn, block=True) await db.execute_write_fn(write_fn, block=True)
@pytest.mark.asyncio
async def test_mtime_ns(db):
assert isinstance(db.mtime_ns, int)
def test_mtime_ns_is_none_for_memory(app_client):
memory_db = Database(app_client.ds, is_memory=True)
assert None is memory_db.mtime_ns