import unittest

from testdoc.finder import find_tests


class MockFinder(object):
    def __init__(self):
        self.log = []

    def got_module(self, module):
        self.log.append(('module', module))

    def got_test_class(self, klass):
        self.log.append(('class', klass))

    def got_test(self, method):
        self.log.append(('method', method))


class TestFinder(unittest.TestCase):

    def setUp(self):
        self.finder = MockFinder()

    def test_empty(self):
        from testdoc.tests import empty
        find_tests(self.finder, empty)
        self.assertEqual(self.finder.log, [('module', empty)])

    def test_hasemptycase(self):
        from testdoc.tests import hasemptycase
        find_tests(self.finder, hasemptycase)
        self.assertEqual(
            self.finder.log, [
                ('module', hasemptycase),
                ('class', hasemptycase.SomeTest)])

    def test_hastests(self):
        from testdoc.tests import hastests
        find_tests(self.finder, hastests)
        self.assertEqual(
            self.finder.log, [
                ('module', hastests),
                ('class', hastests.SomeTest),
                ('method', hastests.SomeTest.test_foo_handles_qux),
                ('method', hastests.SomeTest.test_bar),
                ('class', hastests.AnotherTest),
                ('method', hastests.AnotherTest.test_baz)])

import unittest

from testdoc.finder import find_tests


class MockCollector(object):
    def __init__(self):
        self.log = []

    def got_module(self, module):
        self.log.append(('module', module))

    def got_test_class(self, klass):
        self.log.append(('class', klass))

    def got_test(self, method):
        self.log.append(('method', method))


class TestPassiveFinder(unittest.TestCase):
    """One approach to finding tests is to look inside a module for test
    classes and then look inside those test classes for test methods. The
    default finder uses this approach.
    """

    def setUp(self):
        self.collector = MockCollector()

    def test_empty(self):
        from testdoc.tests import empty
        find_tests(self.collector, empty)
        self.assertEqual(self.collector.log, [('module', empty)])

    def test_hasemptycase(self):
        from testdoc.tests import hasemptycase
        find_tests(self.collector, hasemptycase)
        self.assertEqual(
            self.collector.log, [
                ('module', hasemptycase),
                ('class', hasemptycase.SomeTest)])

    def test_hastests(self):
        from testdoc.tests import hastests
        find_tests(self.collector, hastests)
        self.assertEqual(
            self.collector.log, [
                ('module', hastests),
                ('class', hastests.SomeTest),
                ('method', hastests.SomeTest.test_foo_handles_qux),
                ('method', hastests.SomeTest.test_bar),
                ('class', hastests.AnotherTest),
                ('method', hastests.AnotherTest.test_baz)])

Document finder tests better and use better terminology (the thing that collects found objects isn't a finder, it's a collector)
Document finder tests better and use better terminology (the thing that
collects found objects isn't a finder, it's a collector)

  import unittest
  
  from testdoc.finder import find_tests
  
  
- class MockFinder(object):
+ class MockCollector(object):
      def __init__(self):
          self.log = []
  
      def got_module(self, module):
          self.log.append(('module', module))
  
      def got_test_class(self, klass):
          self.log.append(('class', klass))
  
      def got_test(self, method):
          self.log.append(('method', method))
  
  
- class TestFinder(unittest.TestCase):
+ class TestPassiveFinder(unittest.TestCase):
+     """One approach to finding tests is to look inside a module for test
+     classes and then look inside those test classes for test methods. The
+     default finder uses this approach.
+     """
  
      def setUp(self):
-         self.finder = MockFinder()
+         self.collector = MockCollector()
  
      def test_empty(self):
          from testdoc.tests import empty
-         find_tests(self.finder, empty)
+         find_tests(self.collector, empty)
-         self.assertEqual(self.finder.log, [('module', empty)])
+         self.assertEqual(self.collector.log, [('module', empty)])
  
      def test_hasemptycase(self):
          from testdoc.tests import hasemptycase
-         find_tests(self.finder, hasemptycase)
+         find_tests(self.collector, hasemptycase)
          self.assertEqual(
-             self.finder.log, [
+             self.collector.log, [
                  ('module', hasemptycase),
                  ('class', hasemptycase.SomeTest)])
  
      def test_hastests(self):
          from testdoc.tests import hastests
-         find_tests(self.finder, hastests)
+         find_tests(self.collector, hastests)
          self.assertEqual(
-             self.finder.log, [
+             self.collector.log, [
                  ('module', hastests),
                  ('class', hastests.SomeTest),
                  ('method', hastests.SomeTest.test_foo_handles_qux),
                  ('method', hastests.SomeTest.test_bar),
                  ('class', hastests.AnotherTest),
                  ('method', hastests.AnotherTest.test_baz)])
  
Document finder tests better and use better terminology (the thing that collects found objects isn't a finder, it's a collector)
## Code Before:
import unittest

from testdoc.finder import find_tests


class MockFinder(object):
    def __init__(self):
        self.log = []

    def got_module(self, module):
        self.log.append(('module', module))

    def got_test_class(self, klass):
        self.log.append(('class', klass))

    def got_test(self, method):
        self.log.append(('method', method))


class TestFinder(unittest.TestCase):

    def setUp(self):
        self.finder = MockFinder()

    def test_empty(self):
        from testdoc.tests import empty
        find_tests(self.finder, empty)
        self.assertEqual(self.finder.log, [('module', empty)])

    def test_hasemptycase(self):
        from testdoc.tests import hasemptycase
        find_tests(self.finder, hasemptycase)
        self.assertEqual(
            self.finder.log, [
                ('module', hasemptycase),
                ('class', hasemptycase.SomeTest)])

    def test_hastests(self):
        from testdoc.tests import hastests
        find_tests(self.finder, hastests)
        self.assertEqual(
            self.finder.log, [
                ('module', hastests),
                ('class', hastests.SomeTest),
                ('method', hastests.SomeTest.test_foo_handles_qux),
                ('method', hastests.SomeTest.test_bar),
                ('class', hastests.AnotherTest),
                ('method', hastests.AnotherTest.test_baz)])

## Instruction:
Document finder tests better and use better terminology (the thing that collects found objects isn't a finder, it's a collector)
## Code After:
import unittest

from testdoc.finder import find_tests


class MockCollector(object):
    def __init__(self):
        self.log = []

    def got_module(self, module):
        self.log.append(('module', module))

    def got_test_class(self, klass):
        self.log.append(('class', klass))

    def got_test(self, method):
        self.log.append(('method', method))


class TestPassiveFinder(unittest.TestCase):
    """One approach to finding tests is to look inside a module for test
    classes and then look inside those test classes for test methods. The
    default finder uses this approach.
    """

    def setUp(self):
        self.collector = MockCollector()

    def test_empty(self):
        from testdoc.tests import empty
        find_tests(self.collector, empty)
        self.assertEqual(self.collector.log, [('module', empty)])

    def test_hasemptycase(self):
        from testdoc.tests import hasemptycase
        find_tests(self.collector, hasemptycase)
        self.assertEqual(
            self.collector.log, [
                ('module', hasemptycase),
                ('class', hasemptycase.SomeTest)])

    def test_hastests(self):
        from testdoc.tests import hastests
        find_tests(self.collector, hastests)
        self.assertEqual(
            self.collector.log, [
                ('module', hastests),
                ('class', hastests.SomeTest),
                ('method', hastests.SomeTest.test_foo_handles_qux),
                ('method', hastests.SomeTest.test_bar),
                ('class', hastests.AnotherTest),
                ('method', hastests.AnotherTest.test_baz)])
