# Path: pubs/endecoder.py
#     BP_ID_KEY = 'ID'
#     BP_ENTRYTYPE_KEY = 'ENTRYTYPE'
#     BP_ID_KEY = 'id'
#     BP_ENTRYTYPE_KEY = 'type'
# BIBFIELD_ORDER = ['author', 'title', 'journal', 'institution', 'publisher',
#                   'year', 'month', 'number', 'volume', 'pages', 'url', 'link',
#                   'doi', 'note', 'abstract']
# def sanitize_citekey(record):
# def customizations(record):
#         def __init__(self, error_msg, bibdata):
#     def encode_metadata(self, metadata):
#     def decode_metadata(self, metadata_raw):
#     def encode_bibdata(self, bibdata, ignore_fields=[]):
#     def _entry_to_bp_entry(self, key, entry, ignore_fields=[]):
#     def decode_bibdata(self, bibstr):
#     def _format_parsing_error(cls, e):
# class EnDecoder(object):
#     class BibDecodingError(Exception):
# 
# Path: pubs/p3.py
#     def input():
#     def _get_raw_stdout():
#     def _get_raw_stderr():
#     def u_maybe(s):
#         def __init__(self, *args, **kwargs):
#         def write(self, s):
#     def _get_fake_stdio_ucontent(stdio):
#         def _print_message(self, message, file=None):
#     def _get_raw_stdout():
#     def _get_raw_stderr():
#     def u_maybe(s):
#         def __init__(self, *args, **kwargs):
#         def write(self, s):
#     def _fake_stdio(additional_out=False):
#     def _get_fake_stdio_ucontent(stdio):
# def isbasestr(obj):
#     class StdIO(io.BytesIO):
#     class ArgumentParser(argparse.ArgumentParser):
#     class StdIO(io.BytesIO):


import unittest
import yaml
import dotdot
from pubs import endecoder
from pubs.p3 import ustr
from fixtures import dummy_metadata
from str_fixtures import bibtex_raw0, metadata_raw0, turing_bib, bibtex_month
        self.assertEqual(entry, entry_from_encode)

    def test_endecode_bibtex_field_order(self):
        decoder = endecoder.EnDecoder()
        entry = decoder.decode_bibdata(bibtex_raw0)
        lines = decoder.encode_bibdata(entry).splitlines()
        self.assertEqual(lines[1].split('=')[0].strip(), 'author')
        self.assertEqual(lines[2].split('=')[0].strip(), 'title')
        self.assertEqual(lines[3].split('=')[0].strip(), 'institution')
        self.assertEqual(lines[4].split('=')[0].strip(), 'publisher')
        self.assertEqual(lines[5].split('=')[0].strip(), 'year')
        self.assertEqual(lines[6].split('=')[0].strip(), 'month')
        self.assertEqual(lines[7].split('=')[0].strip(), 'number')
        self.assertEqual(lines[8].split('=')[0].strip(), 'url')
        self.assertEqual(lines[9].split('=')[0].strip(), 'note')
        self.assertEqual(lines[10].split('=')[0].strip(), 'abstract')

    def test_endecode_link_as_url(self):
        decoder = endecoder.EnDecoder()
        if 'url = ' not in bibtex_raw0:
            raise NotImplementedError(
                'The fixture bibraw0 has been changed; test needs an update.')
        raw_with_link = bibtex_raw0.replace('url = ', 'link = ')
        entry = decoder.decode_bibdata(raw_with_link)
        lines = decoder.encode_bibdata(entry).splitlines()
        self.assertEqual(lines[8].split('=')[0].strip(), 'url')
        self.assertEqual(lines[8].split('=')[1].strip(),
                         '{http://ilpubs.stanford.edu:8090/422/},')

    def test_endecode_bibtex_ignores_fields(self):

# Path: pubs/endecoder.py
#     BP_ID_KEY = 'ID'
#     BP_ENTRYTYPE_KEY = 'ENTRYTYPE'
#     BP_ID_KEY = 'id'
#     BP_ENTRYTYPE_KEY = 'type'
# BIBFIELD_ORDER = ['author', 'title', 'journal', 'institution', 'publisher',
#                   'year', 'month', 'number', 'volume', 'pages', 'url', 'link',
#                   'doi', 'note', 'abstract']
# def sanitize_citekey(record):
# def customizations(record):
#         def __init__(self, error_msg, bibdata):
#     def encode_metadata(self, metadata):
#     def decode_metadata(self, metadata_raw):
#     def encode_bibdata(self, bibdata, ignore_fields=[]):
#     def _entry_to_bp_entry(self, key, entry, ignore_fields=[]):
#     def decode_bibdata(self, bibstr):
#     def _format_parsing_error(cls, e):
# class EnDecoder(object):
#     class BibDecodingError(Exception):
# 
# Path: pubs/p3.py
#     def input():
#     def _get_raw_stdout():
#     def _get_raw_stderr():
#     def u_maybe(s):
#         def __init__(self, *args, **kwargs):
#         def write(self, s):
#     def _get_fake_stdio_ucontent(stdio):
#         def _print_message(self, message, file=None):
#     def _get_raw_stdout():
#     def _get_raw_stderr():
#     def u_maybe(s):
#         def __init__(self, *args, **kwargs):
#         def write(self, s):
#     def _fake_stdio(additional_out=False):
#     def _get_fake_stdio_ucontent(stdio):
# def isbasestr(obj):
#     class StdIO(io.BytesIO):
#     class ArgumentParser(argparse.ArgumentParser):
#     class StdIO(io.BytesIO):


# Path: tests/test_endecoder.py
import unittest
import yaml
import dotdot
from pubs import endecoder
from pubs.p3 import ustr
from fixtures import dummy_metadata
from str_fixtures import bibtex_raw0, metadata_raw0, turing_bib, bibtex_month

        self.assertEqual(entry, entry_from_encode)

    def test_endecode_bibtex_field_order(self):
        decoder = endecoder.EnDecoder()
        entry = decoder.decode_bibdata(bibtex_raw0)
        lines = decoder.encode_bibdata(entry).splitlines()
        self.assertEqual(lines[1].split('=')[0].strip(), 'author')
        self.assertEqual(lines[2].split('=')[0].strip(), 'title')
        self.assertEqual(lines[3].split('=')[0].strip(), 'institution')
        self.assertEqual(lines[4].split('=')[0].strip(), 'publisher')
        self.assertEqual(lines[5].split('=')[0].strip(), 'year')
        self.assertEqual(lines[6].split('=')[0].strip(), 'month')
        self.assertEqual(lines[7].split('=')[0].strip(), 'number')
        self.assertEqual(lines[8].split('=')[0].strip(), 'url')
        self.assertEqual(lines[9].split('=')[0].strip(), 'note')
        self.assertEqual(lines[10].split('=')[0].strip(), 'abstract')

    def test_endecode_link_as_url(self):
        decoder = endecoder.EnDecoder()
        if 'url = ' not in bibtex_raw0:
            raise NotImplementedError(
                'The fixture bibraw0 has been changed; test needs an update.')
        raw_with_link = bibtex_raw0.replace('url = ', 'link = ')
        entry = decoder.decode_bibdata(raw_with_link)
        lines = decoder.encode_bibdata(entry).splitlines()
        self.assertEqual(lines[8].split('=')[0].strip(), 'url')
        self.assertEqual(lines[8].split('=')[1].strip(),
                         '{http://ilpubs.stanford.edu:8090/422/},')

    def test_endecode_bibtex_ignores_fields(self):

        decoder = endecoder.EnDecoder()