"""Unit tests for cat2cohort."""

import unittest
from wm_metrics.cat2cohort import api_url, _make_CSV_line, _userlist_to_CSV_cohort


class TestCat2Cohort(unittest.TestCase):

    """Test methods from Cat2Cohort."""

    def test_api_url(self):
        """Test api_url."""
        values = [
            ('fr', 'https://fr.wikipedia.org/w/api.php'),
            ('en', 'https://en.wikipedia.org/w/api.php'),
        ]
        for value, expected in values:
            self.assertEqual(api_url(value), expected)

    def test_make_CSV_line(self):
        """Test _make_CSV_line."""
        values = [
            (('Toto', 'fr'), 'Toto, frwiki'),
            (('Titi', 'en'), 'Titi, enwiki'),
        ]
        for value, expected in values:
            self.assertEqual(_make_CSV_line(*value), expected)

    def test_userlist_to_CSV_cohort(self):
        """Test _userlist_to_CSV_cohort."""
        expected = '\n'.join(self.csvlines)
        self.assertEqual(_userlist_to_CSV_cohort(self.userlist),
                         expected)

"""Unit tests for cat2cohort."""

import unittest
from wm_metrics.cat2cohort import api_url, _make_CSV_line, _userlist_to_CSV_cohort


class TestCat2Cohort(unittest.TestCase):

    """Test methods from Cat2Cohort."""

    def setUp(self):
        """Set up the tests."""
        self.userlist = [('Toto', 'fr'), ('Titi', 'en')]
        self.csvlines = ['Toto, frwiki', 'Titi, enwiki']

    def test_api_url(self):
        """Test api_url."""
        values = [
            ('fr', 'https://fr.wikipedia.org/w/api.php'),
            ('en', 'https://en.wikipedia.org/w/api.php'),
        ]
        for value, expected in values:
            self.assertEqual(api_url(value), expected)

    def test_make_CSV_line(self):
        """Test _make_CSV_line."""
        for value, expected in zip(self.userlist, self.csvlines):
            self.assertEqual(_make_CSV_line(*value), expected)

    def test_userlist_to_CSV_cohort(self):
        """Test _userlist_to_CSV_cohort."""
        expected = '\n'.join(self.csvlines)
        self.assertEqual(_userlist_to_CSV_cohort(self.userlist),
                         expected)

Move unit tests data in setUp
Move unit tests data in setUp

When unit testing the various methods of cat2cohort,
we need some example data (input and expected output).
It makes sense to share it among testing methods through
the setUp method mechanism.

  """Unit tests for cat2cohort."""
  
  import unittest
  from wm_metrics.cat2cohort import api_url, _make_CSV_line, _userlist_to_CSV_cohort
  
  
  class TestCat2Cohort(unittest.TestCase):
  
      """Test methods from Cat2Cohort."""
+ 
+     def setUp(self):
+         """Set up the tests."""
+         self.userlist = [('Toto', 'fr'), ('Titi', 'en')]
+         self.csvlines = ['Toto, frwiki', 'Titi, enwiki']
  
      def test_api_url(self):
          """Test api_url."""
          values = [
              ('fr', 'https://fr.wikipedia.org/w/api.php'),
              ('en', 'https://en.wikipedia.org/w/api.php'),
          ]
          for value, expected in values:
              self.assertEqual(api_url(value), expected)
  
      def test_make_CSV_line(self):
          """Test _make_CSV_line."""
+         for value, expected in zip(self.userlist, self.csvlines):
-         values = [
-             (('Toto', 'fr'), 'Toto, frwiki'),
-             (('Titi', 'en'), 'Titi, enwiki'),
-         ]
-         for value, expected in values:
              self.assertEqual(_make_CSV_line(*value), expected)
  
      def test_userlist_to_CSV_cohort(self):
          """Test _userlist_to_CSV_cohort."""
          expected = '\n'.join(self.csvlines)
          self.assertEqual(_userlist_to_CSV_cohort(self.userlist),
                           expected)
  
Move unit tests data in setUp
## Code Before:
"""Unit tests for cat2cohort."""

import unittest
from wm_metrics.cat2cohort import api_url, _make_CSV_line, _userlist_to_CSV_cohort


class TestCat2Cohort(unittest.TestCase):

    """Test methods from Cat2Cohort."""

    def test_api_url(self):
        """Test api_url."""
        values = [
            ('fr', 'https://fr.wikipedia.org/w/api.php'),
            ('en', 'https://en.wikipedia.org/w/api.php'),
        ]
        for value, expected in values:
            self.assertEqual(api_url(value), expected)

    def test_make_CSV_line(self):
        """Test _make_CSV_line."""
        values = [
            (('Toto', 'fr'), 'Toto, frwiki'),
            (('Titi', 'en'), 'Titi, enwiki'),
        ]
        for value, expected in values:
            self.assertEqual(_make_CSV_line(*value), expected)

    def test_userlist_to_CSV_cohort(self):
        """Test _userlist_to_CSV_cohort."""
        expected = '\n'.join(self.csvlines)
        self.assertEqual(_userlist_to_CSV_cohort(self.userlist),
                         expected)

## Instruction:
Move unit tests data in setUp
## Code After:
"""Unit tests for cat2cohort."""

import unittest
from wm_metrics.cat2cohort import api_url, _make_CSV_line, _userlist_to_CSV_cohort


class TestCat2Cohort(unittest.TestCase):

    """Test methods from Cat2Cohort."""

    def setUp(self):
        """Set up the tests."""
        self.userlist = [('Toto', 'fr'), ('Titi', 'en')]
        self.csvlines = ['Toto, frwiki', 'Titi, enwiki']

    def test_api_url(self):
        """Test api_url."""
        values = [
            ('fr', 'https://fr.wikipedia.org/w/api.php'),
            ('en', 'https://en.wikipedia.org/w/api.php'),
        ]
        for value, expected in values:
            self.assertEqual(api_url(value), expected)

    def test_make_CSV_line(self):
        """Test _make_CSV_line."""
        for value, expected in zip(self.userlist, self.csvlines):
            self.assertEqual(_make_CSV_line(*value), expected)

    def test_userlist_to_CSV_cohort(self):
        """Test _userlist_to_CSV_cohort."""
        expected = '\n'.join(self.csvlines)
        self.assertEqual(_userlist_to_CSV_cohort(self.userlist),
                         expected)
