mirror of
https://github.com/ankitects/anki.git
synced 2025-09-21 15:32:23 -04:00
fix media test
This commit is contained in:
parent
908c514e58
commit
354fbd33f6
1 changed files with 8 additions and 6 deletions
|
@ -71,9 +71,11 @@ def test_changes():
|
||||||
d = getEmptyCol()
|
d = getEmptyCol()
|
||||||
assert d.media._changed()
|
assert d.media._changed()
|
||||||
def added():
|
def added():
|
||||||
return d.media.db.execute("select fname from log where type = 0")
|
return d.media.db.execute("select fname from media where csum is not null")
|
||||||
|
def removed():
|
||||||
|
return d.media.db.execute("select fname from media where csum is null")
|
||||||
assert not list(added())
|
assert not list(added())
|
||||||
assert not list(d.media.removed())
|
assert not list(removed())
|
||||||
# add a file
|
# add a file
|
||||||
dir = tempfile.mkdtemp(prefix="anki")
|
dir = tempfile.mkdtemp(prefix="anki")
|
||||||
path = os.path.join(dir, u"foo.jpg")
|
path = os.path.join(dir, u"foo.jpg")
|
||||||
|
@ -83,24 +85,24 @@ def test_changes():
|
||||||
# should have been logged
|
# should have been logged
|
||||||
d.media.findChanges()
|
d.media.findChanges()
|
||||||
assert list(added())
|
assert list(added())
|
||||||
assert not list(d.media.removed())
|
assert not list(removed())
|
||||||
# if we modify it, the cache won't notice
|
# if we modify it, the cache won't notice
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
open(path, "w").write("world")
|
open(path, "w").write("world")
|
||||||
assert len(list(added())) == 1
|
assert len(list(added())) == 1
|
||||||
assert not list(d.media.removed())
|
assert not list(removed())
|
||||||
# but if we add another file, it will
|
# but if we add another file, it will
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
open(path+"2", "w").write("yo")
|
open(path+"2", "w").write("yo")
|
||||||
d.media.findChanges()
|
d.media.findChanges()
|
||||||
assert len(list(added())) == 2
|
assert len(list(added())) == 2
|
||||||
assert not list(d.media.removed())
|
assert not list(removed())
|
||||||
# deletions should get noticed too
|
# deletions should get noticed too
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
os.unlink(path+"2")
|
os.unlink(path+"2")
|
||||||
d.media.findChanges()
|
d.media.findChanges()
|
||||||
assert len(list(added())) == 1
|
assert len(list(added())) == 1
|
||||||
assert len(list(d.media.removed())) == 1
|
assert len(list(removed())) == 1
|
||||||
|
|
||||||
def test_illegal():
|
def test_illegal():
|
||||||
d = getEmptyCol()
|
d = getEmptyCol()
|
||||||
|
|
Loading…
Reference in a new issue