class CitationTest4(unittest.TestCase):

    def setUp(self):
        fixture = os.path.join("fixtures", "4", "CITATION.cff")
        with open(fixture, "r") as f:
            cffstr = f.read()
        self.citation = Citation(cffstr=cffstr, instantiate_empty=True)

    def test_conversion_to_yaml(self):
        with self.assertRaises(ValueError) as context:
            self.citation._parse_yaml()

        self.assertTrue('Provided CITATION.cff does not seem valid YAML.' in str(context.exception))
class CitationTestOverride(unittest.TestCase):

    def setUp(self):
        # with override
        override = {
            "doi": "thebestdoi.23678237",
            "date-released": datetime.datetime.strptime("2018-03-05", "%Y-%m-%d").date()
        }
        fixture = os.path.join("fixtures", "1", "CITATION.cff")
        with open(fixture, "r") as f:
            cffstr = f.read()
        self.citation = Citation(cffstr=cffstr, instantiate_empty=True, override=override)
        self.citation._parse_yaml()
        self.citation._override_suspect_keys()

    def test_printing_as_bibtex(self):
        fixture = os.path.join("fixtures", "5", "bibtex.bib")
        with open(fixture, "r") as f:
            expected_bibtex = f.read()
        actual_bibtex = self.citation.as_bibtex()
        self.assertEqual(expected_bibtex, actual_bibtex)

    def test_printing_as_codemeta(self):
        fixture = os.path.join("fixtures", "5", "codemeta.json")
        with open(fixture, "r") as f:
            expected_codemeta = f.read()
        actual_codemeta = self.citation.as_codemeta()
        self.assertEqual(expected_codemeta, actual_codemeta)

    def test_printing_as_enw(self):
        fixture = os.path.join("fixtures", "5", "endnote.enw")
        with open(fixture, "r") as f:
            expected_endnote = f.read()
        actual_endnote = self.citation.as_enw()
        self.assertEqual(expected_endnote, actual_endnote)

    def test_printing_as_ris(self):
        fixture = os.path.join("fixtures", "5", "ris.txt")
        with open(fixture, "r") as f:
            expected_ris = f.read()
        actual_ris = self.citation.as_ris()
        self.assertEqual(expected_ris, actual_ris)
class CitationTestRemoveNonExistentKey(unittest.TestCase):

    def setUp(self):
        # trying to remove a key that doesn't exist
        remove = ["hjjshbdjsu3933"]
        fixture = os.path.join("fixtures", "1", "CITATION.cff")
        with open(fixture, "r") as f:
            cffstr = f.read()
        self.citation = Citation(cffstr=cffstr, instantiate_empty=True, remove=remove)
        self.citation._parse_yaml()
        self.citation._remove_suspect_keys()

    def test_printing_as_bibtex(self):
        fixture = os.path.join("fixtures", "1", "bibtex.bib")
        with open(fixture, "r") as f:
            expected_bibtex = f.read()
        actual_bibtex = self.citation.as_bibtex()
        self.assertEqual(expected_bibtex, actual_bibtex)

    def test_printing_as_codemeta(self):
        fixture = os.path.join("fixtures", "1", "codemeta.json")
        with open(fixture, "r") as f:
            expected_codemeta = f.read()
        actual_codemeta = self.citation.as_codemeta()
        self.assertEqual(expected_codemeta, actual_codemeta)

    def test_printing_as_enw(self):
        fixture = os.path.join("fixtures", "1", "endnote.enw")
        with open(fixture, "r") as f:
            expected_endnote = f.read()
        actual_endnote = self.citation.as_enw()
        self.assertEqual(expected_endnote, actual_endnote)

    def test_printing_as_ris(self):
        fixture = os.path.join("fixtures", "1", "ris.txt")
        with open(fixture, "r") as f:
            expected_ris = f.read()
        actual_ris = self.citation.as_ris()
        self.assertEqual(expected_ris, actual_ris)
class CitationTestRemoveSuspectKeyVersion(unittest.TestCase):

    def setUp(self):
        # with removal of suspect key "version"
        remove = ["version"]
        fixture = os.path.join("fixtures", "6", "CITATION.cff")
        with open(fixture, "r") as f:
            cffstr = f.read()
        self.citation = Citation(cffstr=cffstr, instantiate_empty=True, remove=remove)
        self.citation._parse_yaml()
        self.citation._remove_suspect_keys()

    def test_printing_as_bibtex(self):
        fixture = os.path.join("fixtures", "6", "bibtex-no-version.bib")
        with open(fixture, "r") as f:
            expected_bibtex = f.read()
        actual_bibtex = self.citation.as_bibtex()
        self.assertEqual(expected_bibtex, actual_bibtex)

    def test_printing_as_codemeta(self):
        fixture = os.path.join("fixtures", "6", "codemeta-no-version.json")
        with open(fixture, "r") as f:
            expected_codemeta = f.read()
        actual_codemeta = self.citation.as_codemeta()
        self.assertEqual(expected_codemeta, actual_codemeta)

    def test_printing_as_enw(self):
        fixture = os.path.join("fixtures", "6", "endnote-no-version.enw")
        with open(fixture, "r") as f:
            expected_endnote = f.read()
        actual_endnote = self.citation.as_enw()
        self.assertEqual(expected_endnote, actual_endnote)

    def test_printing_as_ris(self):
        fixture = os.path.join("fixtures", "6", "ris-no-version.txt")
        with open(fixture, "r") as f:
            expected_ris = f.read()
        actual_ris = self.citation.as_ris()
        self.assertEqual(expected_ris, actual_ris)