# coding: utf-8

import unittest

import pronto


class TestXref(unittest.TestCase):

    def setUp(self):
        self.x1 = pronto.Xref("PMC:5392374")
        self.x2 = pronto.Xref("PMC:5392374")
        self.x3 = pronto.Xref("PMC:5706746")

    def test_repr(self):
        x1 = pronto.Xref("PMC:5392374")
        self.assertEqual(repr(x1), "Xref('PMC:5392374')")

    def test_eq(self):
        self.assertTrue(self.x1 == self.x2)
        self.assertFalse(self.x1 == self.x3)
        self.assertFalse(self.x1 == 1)

    def test_ne(self):
        self.assertFalse(self.x1 != self.x2)
        self.assertTrue(self.x1 != self.x3)
        self.assertTrue(self.x1 != 1)

    def test_lt(self):
        self.assertFalse(self.x1 < self.x2)
        self.assertTrue(self.x1 < self.x3)
        with self.assertRaises(TypeError):
            self.x1 < 1

    def test_le(self):
        self.assertTrue(self.x1 <= self.x2)
        self.assertTrue(self.x1 <= self.x3)
        with self.assertRaises(TypeError):
            self.x1 <= 1

    def test_gt(self):
        self.assertFalse(self.x2 > self.x2)
        self.assertTrue(self.x3 > self.x1)
        with self.assertRaises(TypeError):
            self.x1 > 1

    def test_ge(self):
        self.assertTrue(self.x1 >= self.x2)
        self.assertTrue(self.x3 >= self.x1)
        with self.assertRaises(TypeError):
            self.x1 >= 1

    def test_init(self):
        with self.assertRaises(ValueError):
            pronto.Xref("PMC SOMETHING")
        with self.assertRaises(TypeError):
            pronto.Xref(1)
        with self.assertRaises(TypeError):
            pronto.Xref("PMC:5392374", 1)

@@ -27,16 +27,31 @@
 ittest%0A%0A
+import fastobo%0A
 import p
@@ -1655,12 +1655,507 @@
 392374%22, 1)%0A
+%0A    def test_from_ast(self):%0A        ast1 = fastobo.xref.Xref(fastobo.id.parse(%22GO:0099545%22))%0A        x1 = Xref._from_ast(ast1)%0A        self.assertEqual(x1.id, %22GO:0099545%22)%0A        self.assertIs(x1.description, None)%0A%0A        ast2 = fastobo.xref.Xref(fastobo.id.parse(%22GO:0099545%22), %22positive regulation of granuloma formation%22)%0A        x2 = Xref._from_ast(ast2)%0A        self.assertEqual(x2.id, %22GO:0099545%22)%0A        self.assertIs(x2.description, %22positive regulation of granuloma formation%22)%0A

Add tests for `fastobo.Xref._from_ast`