Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migrate from nose to pytest #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions mwtypes/files/tests/test_functions.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import io
import os

from nose.tools import eq_, raises
from pytest import raises

from ..functions import concat, extract_extension, normalize_path, reader

Expand All @@ -11,27 +11,27 @@ def test_concat():
f = io.StringIO("Foobar2")
end = "Foobar3"

eq_(concat(start, f, end).read(), "Foobar1Foobar2Foobar3")
assert concat(start, f, end).read() == "Foobar1Foobar2Foobar3"


def test_extract_extension():
eq_(extract_extension("foo")[1], None)
eq_(extract_extension("foo.xml")[1], "xml")
eq_(extract_extension("foo.xml.gz")[1], "gz")
eq_(extract_extension("foo.xml.bz2")[1], "bz2")
eq_(extract_extension("foo.xml-p10001p10200.7z")[1], "7z")
assert extract_extension("foo")[1] == None
assert extract_extension("foo.xml")[1] == "xml"
assert extract_extension("foo.xml.gz")[1] == "gz"
assert extract_extension("foo.xml.bz2")[1] == "bz2"
assert extract_extension("foo.xml-p10001p10200.7z")[1] == "7z"


@raises(FileNotFoundError)
def test_normalize_path_noexist():
normalize_path("IDONTEXIST!!!")
with raises(FileNotFoundError):
normalize_path("IDONTEXIST!!!")


@raises(IsADirectoryError)
def test_normalize_path_directory():
normalize_path(os.path.dirname(__file__))
with raises(IsADirectoryError):
normalize_path(os.path.dirname(__file__))


def test_open():
f = io.StringIO()
eq_(f, reader(f))
assert f == reader(f)
4 changes: 1 addition & 3 deletions mwtypes/files/tests/test_p7z.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import os.path

from nose.tools import eq_

from ..p7z import reader


def test_open_file():
f = reader(os.path.join(os.path.dirname(__file__), "foo.7z"))
eq_(f.read(), "foo\n")
assert f.read() == "foo\n"
116 changes: 57 additions & 59 deletions mwtypes/tests/test_log_item.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import pickle

from nose.tools import eq_

from ..log_item import Deleted, LogItem, Page
from ..timestamp import Timestamp
from ..user import User
Expand All @@ -10,16 +8,16 @@
def test_log_item():
# No info
l = LogItem(10, Timestamp("20150101000000"))
eq_(l.id, 10)
eq_(l.timestamp, Timestamp("20150101000000"))
eq_(l.comment, None)
eq_(l.user, None)
eq_(l.page, None)
eq_(l.type, None)
eq_(l.action, None)
eq_(l.text, None)
eq_(l.params, None)
eq_(l.deleted, None)
assert l.id == 10
assert l.timestamp == Timestamp("20150101000000")
assert l.comment == None
assert l.user == None
assert l.page == None
assert l.type == None
assert l.action == None
assert l.text == None
assert l.params == None
assert l.deleted == None

# All info
l = LogItem(10, Timestamp("20150101000000"),
Expand All @@ -32,73 +30,73 @@ def test_log_item():
params="I am the params",
deleted=Deleted(action=True, comment=False, user=False,
restricted=False))
eq_(l.id, 10)
eq_(l.timestamp, Timestamp("20150101000000"))
eq_(l.comment, "I have a lovely bunch of ...")
eq_(l.user.id, 10)
eq_(l.user.text, "Foobar")
eq_(l.page.namespace, 0)
eq_(l.page.title, "Anarchism")
eq_(l.type, "foo")
eq_(l.action, "bar")
eq_(l.text, "I am the text")
eq_(l.params, "I am the params")
eq_(l.deleted.action, True)
eq_(l.deleted.comment, False)
eq_(l.deleted.user, False)
eq_(l.deleted.restricted, False)
assert l.id == 10
assert l.timestamp == Timestamp("20150101000000")
assert l.comment == "I have a lovely bunch of ..."
assert l.user.id == 10
assert l.user.text == "Foobar"
assert l.page.namespace == 0
assert l.page.title == "Anarchism"
assert l.type == "foo"
assert l.action == "bar"
assert l.text == "I am the text"
assert l.params == "I am the params"
assert l.deleted.action == True
assert l.deleted.comment == False
assert l.deleted.user == False
assert l.deleted.restricted == False

# JSON and Pickle
eq_(l, LogItem(l.to_json()))
eq_(l, pickle.loads(pickle.dumps(l)))
assert l == LogItem(l.to_json())
assert l == pickle.loads(pickle.dumps(l))


def test_deleted():
# No info
d = Deleted()
eq_(d.action, None)
eq_(d.comment, None)
eq_(d.user, None)
eq_(d.restricted, None)
assert d.action == None
assert d.comment == None
assert d.user == None
assert d.restricted == None

# Just one
d = Deleted(action=True)
eq_(d.action, True)
eq_(d.comment, None)
eq_(d.user, None)
eq_(d.restricted, None)
assert d.action == True
assert d.comment == None
assert d.user == None
assert d.restricted == None

# All
d = Deleted(action=True, comment=False, user=True, restricted=False)
eq_(d.action, True)
eq_(d.comment, False)
eq_(d.user, True)
eq_(d.restricted, False)
assert d.action == True
assert d.comment == False
assert d.user == True
assert d.restricted == False

d = Deleted.from_int(0)
eq_(d.action, False)
eq_(d.comment, False)
eq_(d.user, False)
eq_(d.restricted, False)
assert d.action == False
assert d.comment == False
assert d.user == False
assert d.restricted == False

d = Deleted.from_int(3)
eq_(d.action, True)
eq_(d.comment, True)
eq_(d.user, False)
eq_(d.restricted, False)
assert d.action == True
assert d.comment == True
assert d.user == False
assert d.restricted == False

d = Deleted.from_int(9)
eq_(d.action, True)
eq_(d.comment, False)
eq_(d.user, False)
eq_(d.restricted, True)
assert d.action == True
assert d.comment == False
assert d.user == False
assert d.restricted == True

d = Deleted.from_int(15)
eq_(d.action, True)
eq_(d.comment, True)
eq_(d.user, True)
eq_(d.restricted, True)
assert d.action == True
assert d.comment == True
assert d.user == True
assert d.restricted == True

# JSON and Pickle
eq_(d, Deleted(d.to_json()))
eq_(d, pickle.loads(pickle.dumps(d)))
assert d == Deleted(d.to_json())
assert d == pickle.loads(pickle.dumps(d))
30 changes: 14 additions & 16 deletions mwtypes/tests/test_namespace.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,28 @@
import pickle

from nose.tools import eq_

from ..namespace import Namespace


def test_namespace():
# Minimal arguments
n = Namespace(10, 'Foobar')
eq_(n.id, 10)
eq_(n.name, 'Foobar')
eq_(n.aliases, None)
eq_(n.case, None)
eq_(n.canonical, None)
eq_(n.content, None)
assert n.id == 10
assert n.name == 'Foobar'
assert n.aliases == None
assert n.case == None
assert n.canonical == None
assert n.content == None

# All the arguments
n = Namespace(10, 'Foobar', aliases={'Foob', 'Bar'}, case='first-upper',
canonical='Ferpbar', content=False)
eq_(n.id, 10)
eq_(n.name, 'Foobar')
eq_(n.aliases, {'Foob', 'Bar'})
eq_(n.case, "first-upper")
eq_(n.canonical, "Ferpbar")
eq_(n.content, False)
assert n.id == 10
assert n.name == 'Foobar'
assert n.aliases == {'Foob', 'Bar'}
assert n.case == "first-upper"
assert n.canonical == "Ferpbar"
assert n.content == False

# JSON and Pickle
eq_(n, Namespace(n.to_json()))
eq_(n, pickle.loads(pickle.dumps(n)))
assert n == Namespace(n.to_json())
assert n == pickle.loads(pickle.dumps(n))
Loading