Skip to content

Commit

Permalink
code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
Knio committed Oct 24, 2014
1 parent 1108c34 commit 0b2f974
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 75 deletions.
2 changes: 1 addition & 1 deletion karchive/array.py
Expand Up @@ -72,7 +72,7 @@ def __setitem__(self, i, v):
def getslice(self, i):
raise NotImplementedError

def setslice(self, i):
def setslice(self, i, v):
raise NotImplementedError

def extend(self, iter):
Expand Down
54 changes: 0 additions & 54 deletions karchive/blockview.py

This file was deleted.

20 changes: 0 additions & 20 deletions karchive/fileobject.py

This file was deleted.

36 changes: 36 additions & 0 deletions tests/test_array.py
@@ -1,5 +1,7 @@
import os

import pytest

import karchive

TEST_NAME = 'test_archive.deleteme.dat'
Expand All @@ -10,6 +12,16 @@ def test_array():
ar = db.array('I')
r = ar.root

with pytest.raises(IndexError):
x = ar.pop()

with pytest.raises(NotImplementedError):
x = ar[0:1]

with pytest.raises(NotImplementedError):
ar[0:1] = [1]


N = 2000
for i in range(N):
ar.append(i)
Expand Down Expand Up @@ -62,6 +74,30 @@ def test_array():
os.remove(TEST_NAME)


def test_todo():
db = karchive.Database(TEST_NAME, overwrite=True)
db.freelist = []
ar = db.array('I')
r = ar.root

with pytest.raises(IndexError):
x = ar.pop()

with pytest.raises(NotImplementedError):
x = ar[0:1]

with pytest.raises(NotImplementedError):
ar[0:1] = [1]

with pytest.raises(NotImplementedError):
ar.extend([1])


ar.close()
db.close()
os.remove(TEST_NAME)



if __name__ == '__main__':
test_array()
27 changes: 27 additions & 0 deletions tests/test_blob.py
Expand Up @@ -2,6 +2,8 @@
import time
import random

import pytest

import karchive

TEST_NAME = 'test_archive.deleteme.dat'
Expand All @@ -10,6 +12,21 @@ def test_small_blob():
db = karchive.Database(TEST_NAME, overwrite=True)
blob = db.blob()

with pytest.raises(AttributeError):
x = blob.foobar

with pytest.raises(ValueError):
x = blob.get_blocks(1, 0)

with pytest.raises(ValueError):
x = blob.get_blocks(0, 1)

with pytest.raises(ValueError):
x = blob.get_host_index(0)

with pytest.raises(ValueError):
x = blob.allocate(0)

blob.resize(5)
assert len(blob) == 5
blob.write(0, b'AAAAA')
Expand All @@ -35,6 +52,16 @@ def test_small_blob():
assert len(blob) == 6
assert blob.read() == b'AACAAB'

blob.resize(1024 * 1024 * 32)
blob.resize(1024 * 1024 * 8)
blob.resize(4096)

with pytest.raises(IndexError):
x = blob.get_host_index(1)

blob.resize(0)
assert blob.read() == b''

db.close()
os.remove(TEST_NAME)

Expand Down
2 changes: 2 additions & 0 deletions tests/test_freelist.py
Expand Up @@ -110,6 +110,8 @@ def test_freelist():



host.close()
os.remove(TEST_NAME)
return
assert False

Expand Down
6 changes: 6 additions & 0 deletions tests/test_hash.py
@@ -1,5 +1,7 @@
import os

import pytest

import karchive

TEST_NAME = 'test_archive.deleteme.dat'
Expand Down Expand Up @@ -43,9 +45,13 @@ def test_hash():
for i in range(N-1, -1, -1):
assert hs.pop(i) == i

with pytest.raises(KeyError):
x = hs.pop(1)

hs.close()
db.close()

os.remove(TEST_NAME)


if __name__ == '__main__':
Expand Down

0 comments on commit 0b2f974

Please sign in to comment.