diff options
author | Jon Bernard <jbernard@tuxion.com> | 2015-12-30 06:42:10 -0500 |
---|---|---|
committer | Jon Bernard <jbernard@tuxion.com> | 2015-12-30 07:30:06 -0500 |
commit | 51128934d96bdda824a67b6d35ffed997e887839 (patch) | |
tree | fbe7fb730ea83bb5e389a90e1e9995e8f20b2b64 /tests/test_dotfile.py | |
parent | 3c4a553e4c45f5232f971d664445e07ee94a074a (diff) | |
download | dotfiles-51128934d96bdda824a67b6d35ffed997e887839.tar.gz dotfiles-51128934d96bdda824a67b6d35ffed997e887839.tar.bz2 dotfiles-51128934d96bdda824a67b6d35ffed997e887839.zip |
Use pytest parametrize to simplify tests
Diffstat (limited to 'tests/test_dotfile.py')
-rw-r--r-- | tests/test_dotfile.py | 106 |
1 files changed, 33 insertions, 73 deletions
diff --git a/tests/test_dotfile.py b/tests/test_dotfile.py index b854859..e679caf 100644 --- a/tests/test_dotfile.py +++ b/tests/test_dotfile.py @@ -3,34 +3,21 @@ import py.error from dotfiles.dotfile import Dotfile -class TestAdd: +@pytest.mark.parametrize("times", range(1, 4)) +def test_add(tmpdir, times): - def test_add(self, tmpdir): + repo = tmpdir.ensure("Dotfiles", dir=1) + name = tmpdir.ensure(".vimrc") + target = repo.join("vimrc") - repo = tmpdir.ensure("Dotfiles", dir=1) - name = tmpdir.ensure(".vimrc") - target = repo.join("vimrc") + dotfile = Dotfile(name, target) + dotfile.add() - dotfile = Dotfile(name, target) - dotfile.add() - - assert target.check(file=1, link=0) - assert name.check(file=1, link=1) - assert name.samefile(target) - - def test_add_twice(self, tmpdir): - - repo = tmpdir.ensure("Dotfiles", dir=1) - name = tmpdir.ensure(".vimrc") - target = repo.join("vimrc") - - dotfile = Dotfile(name, target) - dotfile.add() - - assert target.check(file=1, link=0) - assert name.check(file=1, link=1) - assert name.samefile(target) + assert target.check(file=1, link=0) + assert name.check(file=1, link=1) + assert name.samefile(target) + for x in range(2, times): with pytest.raises(OSError): dotfile.add() @@ -39,36 +26,22 @@ class TestAdd: assert name.samefile(target) -class TestRemove: - - def test_remove(self, tmpdir): - - repo = tmpdir.ensure("Dotfiles", dir=1) - name = tmpdir.join(".vimrc") - target = repo.ensure("vimrc") - - name.mksymlinkto(target) - - dotfile = Dotfile(name, target) - dotfile.remove() - - assert False == target.check() - assert name.check(file=1, link=0) +@pytest.mark.parametrize("times", range(1, 4)) +def test_remove(tmpdir, times): - def test_remove_twice(self, tmpdir): + repo = tmpdir.ensure("Dotfiles", dir=1) + name = tmpdir.join(".vimrc") + target = repo.ensure("vimrc") - repo = tmpdir.ensure("Dotfiles", dir=1) - name = tmpdir.join(".vimrc") - target = repo.ensure("vimrc") + name.mksymlinkto(target) - name.mksymlinkto(target) + dotfile = Dotfile(name, target) + dotfile.remove() - dotfile = Dotfile(name, target) - dotfile.remove() - - assert False == target.check() - assert name.check(file=1, link=0) + assert False == target.check() + assert name.check(file=1, link=0) + for x in range(2, times): with pytest.raises(OSError): dotfile.remove() @@ -76,34 +49,21 @@ class TestRemove: assert name.check(file=1, link=0) -class TestSync: - - def test_sync(self, tmpdir): - - repo = tmpdir.ensure("Dotfiles", dir=1) - name = tmpdir.join(".vimrc") - target = repo.ensure("vimrc") - - dotfile = Dotfile(name, target) - dotfile.sync() +@pytest.mark.parametrize("times", range(1, 4)) +def test_sync(tmpdir, times): - assert target.check(file=1, link=0) - assert name.check(file=1, link=1) - assert name.samefile(target) - - def test_sync_twice(self, tmpdir): + repo = tmpdir.ensure("Dotfiles", dir=1) + name = tmpdir.join(".vimrc") + target = repo.ensure("vimrc") - repo = tmpdir.ensure("Dotfiles", dir=1) - name = tmpdir.join(".vimrc") - target = repo.ensure("vimrc") + dotfile = Dotfile(name, target) + dotfile.sync() - dotfile = Dotfile(name, target) - dotfile.sync() - - assert target.check(file=1, link=0) - assert name.check(file=1, link=1) - assert name.samefile(target) + assert target.check(file=1, link=0) + assert name.check(file=1, link=1) + assert name.samefile(target) + for x in range(2, times): with pytest.raises(py.error.EEXIST): dotfile.sync() |