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 to pytest #73

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
41 changes: 27 additions & 14 deletions tests/test_config.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
from nose.tools import assert_raises
import pytest

from tarsnapper.config import load_config, ConfigError


def test_empty_config():
assert_raises(ConfigError, load_config, """
with pytest.raises(ConfigError):
load_config("""
deltas: 1d 2d
jobs:
""")
assert_raises(ConfigError, load_config, """
with pytest.raises(ConfigError):
load_config("""
deltas: 1d 2d
""")

Expand Down Expand Up @@ -58,7 +60,8 @@ def test_no_sources():


def test_no_target():
assert_raises(ConfigError, load_config, """
with pytest.raises(ConfigError):
load_config("""
jobs:
foo:
deltas: 1d 2d 3d
Expand Down Expand Up @@ -106,7 +109,8 @@ def test_global_deltas():


def test_target_has_name():
assert_raises(ConfigError, load_config, """
with pytest.raises(ConfigError):
load_config("""
target: $date
jobs:
foo:
Expand All @@ -125,14 +129,16 @@ def test_target_has_name():


def test_target_has_date():
assert_raises(ConfigError, load_config, """
with pytest.raises(ConfigError):
load_config("""
target: $name
jobs:
foo:
sources: /etc
deltas: 1d 2d
""")
assert_raises(ConfigError, load_config, """
with pytest.raises(ConfigError):
load_config("""
jobs:
foo:
target: $name
Expand All @@ -158,7 +164,8 @@ def test_dateformat_inheritance():


def test_unsupported_keys():
assert_raises(ConfigError, load_config, """
with pytest.raises(ConfigError):
load_config("""
jobs:
foo:
target: $date
Expand All @@ -180,7 +187,8 @@ def test_single_source():

def test_source_and_sources():
"""You can't use both options at the same time."""
assert_raises(ConfigError, load_config, """
with pytest.raises(ConfigError):
load_config("""
target: $name-$date
deltas: 1d 2d
jobs:
Expand All @@ -194,7 +202,8 @@ def test_source_and_sources():

def test_alias_and_aliases():
"""You can't use both options at the same time."""
assert_raises(ConfigError, load_config, """
with pytest.raises(ConfigError):
load_config("""
target: $name-$date
deltas: 1d 2d
jobs:
Expand All @@ -208,7 +217,8 @@ def test_alias_and_aliases():

def test_exclude_and_excludes():
"""You can't use both options at the same time."""
assert_raises(ConfigError, load_config, """
with pytest.raises(ConfigError):
load_config("""
target: $name-$date
deltas: 1d 2d
jobs:
Expand Down Expand Up @@ -243,7 +253,8 @@ def test_named_delta():


def test_unspecified_named_delta():
assert_raises(ConfigError, load_config, """
with pytest.raises(ConfigError):
load_config("""
target: $name-$date
delta-names:
myDelta:
Expand All @@ -255,7 +266,8 @@ def test_unspecified_named_delta():


def test_undefined_named_delta():
assert_raises(ConfigError, load_config, """
with pytest.raises(ConfigError):
load_config("""
target: $name-$date
delta-names:
myDelta: 1d 7d 30d
Expand All @@ -268,7 +280,8 @@ def test_undefined_named_delta():

def test_named_delta_and_deltas():
"""You can't use both named delta and deltas at the same time."""
assert_raises(ConfigError, load_config, """
with pytest.raises(ConfigError):
load_config("""
target: $name-$date
delta-names:
myDelta: 1d 7d 30d
Expand Down
4 changes: 2 additions & 2 deletions tests/test_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ def match(self, expect_calls):

class BaseTest(object):

def setup(self):
def setup_method(self):
self.log = logging.getLogger("test_script")
self._tmpdir = tempfile.mkdtemp()
# We need at least a file for tarsnapper to consider a source
# to "exist".
open(path.join(self._tmpdir, '.placeholder'), 'w').close()
self.now = datetime.utcnow()

def teardown(self):
def teardown_method(self):
shutil.rmtree(self._tmpdir)

def run(self, jobs, archives, **args):
Expand Down