<reponame>Defendi/python-cnab

import unittest

import os
import codecs

from unittest import skip

from cnab400 import errors
from cnab400.bancos import bs2
from cnab400.tipos import Arquivo
from tests.data_bs2 import get_bs2_data_from_dict, get_bs2_data_from_file, ARQS_DIRPATH


class TestCnab400(unittest.TestCase):

    def __init__(self, *args, **kwargs):
        super(TestCnab400, self).__init__(*args, **kwargs)
        self.maxDiff = None

    def setUp(self):
        self.bs2_data = get_bs2_data_from_dict()
        self.arquivo = Arquivo(bs2, **self.bs2_data['header'])

    @skip
    def test_unicode(self):
        self.arquivo.incluir_cobranca(**self.bs2_data['cobranca'])
        self.assertEqual(str(self.arquivo), get_bs2_data_from_file())

    def test_empty_data(self):
        arquivo = Arquivo(bs2)
        self.assertRaises(errors.ArquivoVazioError, str, arquivo)

    def test_leitura(self):
        return_file_path = os.path.join(ARQS_DIRPATH, 'cobranca.bs2.ret')
        ret_file = codecs.open(return_file_path, encoding='ascii')
        arquivo = Arquivo(bs2, arquivo=ret_file)
        ret_file.seek(0)
        self.assertEqual(ret_file.read(), str(arquivo))

if __name__ == '__main__':
    unittest.main()

import unittest

import os
import codecs

from unittest import skip

from cnab400 import errors
from cnab400.bancos import bs2
from cnab400.tipos import Arquivo
from tests.data_bs2 import get_bs2_data_from_dict, get_bs2_data_from_file, ARQS_DIRPATH


class TestCnab400(unittest.TestCase):

    def __init__(self, *args, **kwargs):
        super(TestCnab400, self).__init__(*args, **kwargs)
        self.maxDiff = None

    def setUp(self):
        self.bs2_data = get_bs2_data_from_dict()
        self.arquivo = Arquivo(bs2, **self.bs2_data['header'])

    @skip
    def test_unicode(self):
        self.arquivo.incluir_cobranca(**self.bs2_data['cobranca'])
        self.assertEqual(str(self.arquivo), get_bs2_data_from_file())

    def test_empty_data(self):
        arquivo = Arquivo(bs2)
        self.assertRaises(errors.ArquivoVazioError, str, arquivo)

    def test_leitura(self):
        return_file_path = os.path.join(ARQS_DIRPATH, 'cobranca.bs2.ret')
        ret_file = codecs.open(return_file_path, encoding='ascii')
        arquivo = Arquivo(bs2, arquivo=ret_file)
        ret_file.seek(0)
        self.assertEqual(ret_file.read(), str(arquivo))

if __name__ == '__main__':
    unittest.main()