import os.path
from tempfile import mkdtemp
from unittest import TestCase
from unittest.mock import patch
from shutil import copy2

from rosie.chamber_of_deputies import settings
from rosie.chamber_of_deputies.adapter import Adapter


class TestDataset(TestCase):

    def setUp(self):
        temp_path = mkdtemp()
        copy2('rosie/chamber_of_deputies/tests/fixtures/companies.xz',
              os.path.join(temp_path, settings.COMPANIES_DATASET))
        copy2('rosie/chamber_of_deputies/tests/fixtures/reimbursements.xz', temp_path)
        self.subject = Adapter(temp_path)

    @patch('rosie.chamber_of_deputies.adapter.CEAPDataset')
    @patch('rosie.chamber_of_deputies.adapter.fetch')
    def test_get_performs_a_left_merge_between_reimbursements_and_companies(self, _ceap_dataset, _fetch):
        dataset = self.subject.dataset()
        self.assertEqual(5, len(dataset))
        self.assertEqual(1, dataset['legal_entity'].isnull().sum())

import shutil
import os
from tempfile import mkdtemp
from unittest import TestCase
from unittest.mock import patch
from shutil import copy2

from rosie.chamber_of_deputies.adapter import Adapter


class TestDataset(TestCase):

    def setUp(self):
        self.temp_path = mkdtemp()
        fixtures = os.path.join('rosie', 'chamber_of_deputies', 'tests', 'fixtures')
        copies = (
            ('companies.xz', Adapter.COMPANIES_DATASET),
            ('reimbursements.xz', 'reimbursements.xz')
        )
        for source, target in copies:
            copy2(os.path.join(fixtures, source), os.path.join(self.temp_path, target))
        self.subject = Adapter(self.temp_path)

    def tearDown(self):
        shutil.rmtree(self.temp_path)

    @patch('rosie.chamber_of_deputies.adapter.CEAPDataset')
    @patch('rosie.chamber_of_deputies.adapter.fetch')
    def test_get_performs_a_left_merge_between_reimbursements_and_companies(self, fetch, ceap):
        self.assertEqual(5, len(self.subject.dataset))
        self.assertEqual(1, self.subject.dataset['legal_entity'].isnull().sum())

Fix companies path in Chamber of Deputies dataset test
Fix companies path in Chamber of Deputies dataset test

+ import shutil
- import os.path
+ import os
  from tempfile import mkdtemp
  from unittest import TestCase
  from unittest.mock import patch
  from shutil import copy2
  
- from rosie.chamber_of_deputies import settings
  from rosie.chamber_of_deputies.adapter import Adapter
  
  
  class TestDataset(TestCase):
  
      def setUp(self):
-         temp_path = mkdtemp()
+         self.temp_path = mkdtemp()
-         copy2('rosie/chamber_of_deputies/tests/fixtures/companies.xz',
-               os.path.join(temp_path, settings.COMPANIES_DATASET))
-         copy2('rosie/chamber_of_deputies/tests/fixtures/reimbursements.xz', temp_path)
+         fixtures = os.path.join('rosie', 'chamber_of_deputies', 'tests', 'fixtures')
+         copies = (
+             ('companies.xz', Adapter.COMPANIES_DATASET),
+             ('reimbursements.xz', 'reimbursements.xz')
+         )
+         for source, target in copies:
+             copy2(os.path.join(fixtures, source), os.path.join(self.temp_path, target))
-         self.subject = Adapter(temp_path)
+         self.subject = Adapter(self.temp_path)
+ 
+     def tearDown(self):
+         shutil.rmtree(self.temp_path)
  
      @patch('rosie.chamber_of_deputies.adapter.CEAPDataset')
      @patch('rosie.chamber_of_deputies.adapter.fetch')
-     def test_get_performs_a_left_merge_between_reimbursements_and_companies(self, _ceap_dataset, _fetch):
+     def test_get_performs_a_left_merge_between_reimbursements_and_companies(self, fetch, ceap):
-         dataset = self.subject.dataset()
-         self.assertEqual(5, len(dataset))
+         self.assertEqual(5, len(self.subject.dataset))
-         self.assertEqual(1, dataset['legal_entity'].isnull().sum())
+         self.assertEqual(1, self.subject.dataset['legal_entity'].isnull().sum())
  
Fix companies path in Chamber of Deputies dataset test
## Code Before:
import os.path
from tempfile import mkdtemp
from unittest import TestCase
from unittest.mock import patch
from shutil import copy2

from rosie.chamber_of_deputies import settings
from rosie.chamber_of_deputies.adapter import Adapter


class TestDataset(TestCase):

    def setUp(self):
        temp_path = mkdtemp()
        copy2('rosie/chamber_of_deputies/tests/fixtures/companies.xz',
              os.path.join(temp_path, settings.COMPANIES_DATASET))
        copy2('rosie/chamber_of_deputies/tests/fixtures/reimbursements.xz', temp_path)
        self.subject = Adapter(temp_path)

    @patch('rosie.chamber_of_deputies.adapter.CEAPDataset')
    @patch('rosie.chamber_of_deputies.adapter.fetch')
    def test_get_performs_a_left_merge_between_reimbursements_and_companies(self, _ceap_dataset, _fetch):
        dataset = self.subject.dataset()
        self.assertEqual(5, len(dataset))
        self.assertEqual(1, dataset['legal_entity'].isnull().sum())

## Instruction:
Fix companies path in Chamber of Deputies dataset test
## Code After:
import shutil
import os
from tempfile import mkdtemp
from unittest import TestCase
from unittest.mock import patch
from shutil import copy2

from rosie.chamber_of_deputies.adapter import Adapter


class TestDataset(TestCase):

    def setUp(self):
        self.temp_path = mkdtemp()
        fixtures = os.path.join('rosie', 'chamber_of_deputies', 'tests', 'fixtures')
        copies = (
            ('companies.xz', Adapter.COMPANIES_DATASET),
            ('reimbursements.xz', 'reimbursements.xz')
        )
        for source, target in copies:
            copy2(os.path.join(fixtures, source), os.path.join(self.temp_path, target))
        self.subject = Adapter(self.temp_path)

    def tearDown(self):
        shutil.rmtree(self.temp_path)

    @patch('rosie.chamber_of_deputies.adapter.CEAPDataset')
    @patch('rosie.chamber_of_deputies.adapter.fetch')
    def test_get_performs_a_left_merge_between_reimbursements_and_companies(self, fetch, ceap):
        self.assertEqual(5, len(self.subject.dataset))
        self.assertEqual(1, self.subject.dataset['legal_entity'].isnull().sum())
