Skip to content

Commit

Permalink
bug 1361764 - update submitter tests to use pytest (mozilla-services#…
Browse files Browse the repository at this point in the history
  • Loading branch information
willkg authored Aug 29, 2017
1 parent a0ad129 commit 72e02b3
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 64 deletions.
Empty file.
126 changes: 62 additions & 64 deletions socorro/unittest/submitter/test_submitter_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

import mock
import time
import json
import time

from nose.tools import eq_, ok_, assert_raises
from configman.dotdict import DotDict
import mock
import pytest

from socorro.submitter.submitter_app import (
SubmitterApp,
SubmitterFileSystemWalkerSource,
)
from configman.dotdict import DotDict
from socorro.external.crashstorage_base import Redactor
from socorro.unittest.testbase import TestCase

Expand Down Expand Up @@ -56,8 +56,8 @@ def get_standard_config(self):
def test_setup(self):
config = self.get_standard_config()
sub_walker = SubmitterFileSystemWalkerSource(config)
eq_(sub_walker.config, config)
eq_(sub_walker.config.logger, config.logger)
assert sub_walker.config == config
assert sub_walker.config.logger == config.logger

def test_get_raw_crash(self):
config = self.get_standard_config()
Expand All @@ -74,8 +74,8 @@ def test_get_raw_crash(self):
]

raw_crash = sub_walker.get_raw_crash(path_tuple)
ok_(isinstance(raw_crash, DotDict))
eq_(raw_crash['name'], 'Gabi')
assert isinstance(raw_crash, DotDict)
assert raw_crash['name'] == 'Gabi'

def test_get_raw_dumps_as_files(self):
config = self.get_standard_config()
Expand All @@ -98,8 +98,8 @@ def test_get_raw_dumps_as_files(self):
'flash2': '/some/path/6611a662-e70f-4ba5-a397-69a3a2121129.flash2.dump'
}

ok_(isinstance(raw_dumps_files, dict))
eq_(raw_dumps_files, dump_names)
assert isinstance(raw_dumps_files, dict)
assert raw_dumps_files == dump_names

def test_new_crashes(self):
sequence = [
Expand Down Expand Up @@ -191,7 +191,7 @@ def listdir_mock_method(a_path):

sub_walker = SubmitterFileSystemWalkerSource(config)
result = [x for x in sub_walker.new_crashes()]
eq_(result, expected)
assert result == expected


class TestSubmitterApp(TestCase):
Expand Down Expand Up @@ -277,8 +277,8 @@ def get_new_crash_source_config(self):
def test_setup(self):
config = self.get_standard_config()
sub = SubmitterApp(config)
eq_(sub.config, config)
eq_(sub.config.logger, config.logger)
assert sub.config == config
assert sub.config.logger == config.logger

def test_transform(self):
config = self.get_standard_config()
Expand Down Expand Up @@ -319,10 +319,11 @@ def test_source_iterator(self):
sub.source.new_crashes = lambda: iter([1, 2, 3])
itera = sub.source_iterator()

eq_(itera.next(), ((1,), {}))
eq_(itera.next(), ((2,), {}))
eq_(itera.next(), ((3,), {}))
assert_raises(StopIteration, itera.next)
assert itera.next() == ((1,), {})
assert itera.next() == ((2,), {})
assert itera.next() == ((3,), {})
with pytest.raises(StopIteration):
itera.next()

# Test with number of submissions equal to forever
# It never raises StopIterations
Expand All @@ -335,12 +336,12 @@ def test_source_iterator(self):

sub.source.new_crashes = lambda: iter([1, 2, 3])

eq_(itera.next(), ((1,), {}))
eq_(itera.next(), ((2,), {}))
eq_(itera.next(), ((3,), {}))
eq_(itera.next(), ((1,), {}))
eq_(itera.next(), ((2,), {}))
eq_(itera.next(), ((3,), {}))
assert itera.next() == ((1,), {})
assert itera.next() == ((2,), {})
assert itera.next() == ((3,), {})
assert itera.next() == ((1,), {})
assert itera.next() == ((2,), {})
assert itera.next() == ((3,), {})

# Test with number of submissions equal to an integer > number of items
# It raises StopIterations after some number of elements were called
Expand All @@ -353,12 +354,13 @@ def test_source_iterator(self):

sub.source.new_crashes = lambda: iter([1, 2, 3])

eq_(itera.next(), ((1,), {}))
eq_(itera.next(), ((2,), {}))
eq_(itera.next(), ((3,), {}))
eq_(itera.next(), ((1,), {}))
eq_(itera.next(), ((2,), {}))
assert_raises(StopIteration, itera.next)
assert itera.next() == ((1,), {})
assert itera.next() == ((2,), {})
assert itera.next() == ((3,), {})
assert itera.next() == ((1,), {})
assert itera.next() == ((2,), {})
with pytest.raises(StopIteration):
itera.next()

# Test with number of submissions equal to an integer < number of items
# It raises StopIterations after some number of elements were called
Expand All @@ -371,8 +373,9 @@ def test_source_iterator(self):

sub.source.new_crashes = lambda: iter([1, 2, 3])

eq_(itera.next(), ((1,), {}))
assert_raises(StopIteration, itera.next)
assert itera.next() == ((1,), {})
with pytest.raises(StopIteration):
itera.next()

def test_new_crash_source_iterator(self):

Expand All @@ -388,10 +391,11 @@ def test_new_crash_source_iterator(self):
.new_crashes = lambda: iter([1, 2, 3])
itera = sub.source_iterator()

eq_(itera.next(), ((1,), {}))
eq_(itera.next(), ((2,), {}))
eq_(itera.next(), ((3,), {}))
assert_raises(StopIteration, itera.next)
assert itera.next() == ((1,), {})
assert itera.next() == ((2,), {})
assert itera.next() == ((3,), {})
with pytest.raises(StopIteration):
itera.next()

# Test with number of submissions equal to forever
# It never raises StopIterations
Expand All @@ -407,12 +411,12 @@ def test_new_crash_source_iterator(self):
config.new_crash_source.new_crash_source_class.return_value \
.new_crashes = lambda: iter([1, ((2, ), {}), 3])

eq_(itera.next(), ((1,), {}))
eq_(itera.next(), ((2,), {}))
eq_(itera.next(), ((3,), {}))
eq_(itera.next(), ((1,), {}))
eq_(itera.next(), ((2,), {}))
eq_(itera.next(), ((3,), {}))
assert itera.next() == ((1,), {})
assert itera.next() == ((2,), {})
assert itera.next() == ((3,), {})
assert itera.next() == ((1,), {})
assert itera.next() == ((2,), {})
assert itera.next() == ((3,), {})

# Test with number of submissions equal to an integer > number of items
# It raises StopIterations after some number of elements were called
Expand All @@ -427,12 +431,13 @@ def _iter():
return iter([((1, ), {'finished_func': (1,)}), 2, 3])
config.new_crash_source.new_crash_source_class.return_value.new_crashes = _iter

eq_(itera.next(), ((1,), {'finished_func': (1,)}))
eq_(itera.next(), ((2,), {}))
eq_(itera.next(), ((3,), {}))
eq_(itera.next(), ((1,), {'finished_func': (1,)}))
eq_(itera.next(), ((2,), {}))
assert_raises(StopIteration, itera.next)
assert itera.next() == ((1,), {'finished_func': (1,)})
assert itera.next() == ((2,), {})
assert itera.next() == ((3,), {})
assert itera.next() == ((1,), {'finished_func': (1,)})
assert itera.next() == ((2,), {})
with pytest.raises(StopIteration):
itera.next()

# Test with number of submissions equal to an integer < number of items
# It raises StopIterations after some number of elements were called
Expand All @@ -446,8 +451,9 @@ def _iter():
config.new_crash_source.new_crash_source_class.return_value \
.new_crashes = lambda: iter([1, 2, 3])

eq_(itera.next(), ((1,), {}))
assert_raises(StopIteration, itera.next)
assert itera.next() == ((1,), {})
with pytest.raises(StopIteration):
itera.next()

# Test with number of submissions equal to an integer < number of items
# AND the new_crashes iter returning an args, kwargs form rather than
Expand All @@ -460,20 +466,12 @@ def _iter():
sub._setup_task_manager()
itera = sub.source_iterator()

item1 = (((1, ['./1.json', './1.dump', './1.other.dump']), ), {})
item2 = (((2, ['./2.json', './1.dump']), ), {})
config.new_crash_source.new_crash_source_class.return_value \
.new_crashes = lambda: iter(
[
(((1, ['./1.json', './1.dump', './1.other.dump']), ), {}),
(((2, ['./2.json', './1.dump']), ), {})
]
)
.new_crashes = lambda: iter([item1, item2])

eq_(
itera.next(),
(((1, ['./1.json', './1.dump', './1.other.dump']), ), {})
)
eq_(
itera.next(),
(((2, ['./2.json', './1.dump']), ), {})
)
assert_raises(StopIteration, itera.next)
assert itera.next() == item1
assert itera.next() == item2
with pytest.raises(StopIteration):
itera.next()

0 comments on commit 72e02b3

Please sign in to comment.