예제 #1
0
    def __unicode__(self):
        # All fields but attributes (and extra).
        items = [getattr(self, k) for k in constants._gffkeys[:-1]]

        # Handle start/stop, which are either None or int
        if items[3] is None:
            items[3] = "."
        else:
            items[3] = str(items[3])

        if items[4] is None:
            items[4] = "."
        else:
            items[4] = str(items[4])

        # Reconstruct from dict and dialect
        reconstructed_attributes = parser._reconstruct(
            self.attributes, self.dialect, keep_order=self.keep_order,
            sort_attribute_values=self.sort_attribute_values)

        # Final line includes reconstructed as well as any previously-added
        # "extra" fields
        items.append(reconstructed_attributes)
        if self.extra:
            items.append('\t'.join(self.extra))

        return '\t'.join(items)
예제 #2
0
파일: feature.py 프로젝트: arnikz/gffutils
    def __unicode__(self):
        # All fields but attributes (and extra).
        items = [getattr(self, k) for k in constants._gffkeys[:-1]]

        # Handle start/stop, which are either None or int
        if items[3] is None:
            items[3] = "."
        else:
            items[3] = str(items[3])

        if items[4] is None:
            items[4] = "."
        else:
            items[4] = str(items[4])

        # Reconstruct from dict and dialect
        reconstructed_attributes = parser._reconstruct(
            self.attributes, self.dialect, keep_order=self.keep_order,
            sort_attribute_values=self.sort_attribute_values)

        # Final line includes reconstructed as well as any previously-added
        # "extra" fields
        items.append(reconstructed_attributes)
        if self.extra:
            items.append('\t'.join(self.extra))

        return '\t'.join(items)
예제 #3
0
def test_empty_recontruct():
    """
    reconstructing attributes with incomplete information returns empty string
    """
    assert parser._reconstruct(None, constants.dialect) == ""
    assert_raises(exceptions.AttributeStringError, parser._reconstruct, dict(ID='asdf'), None)
    assert_raises(exceptions.AttributeStringError, parser._reconstruct, None, None)
예제 #4
0
def test_empty_recontruct():
    """
    reconstructing attributes with incomplete information returns empty string
    """
    assert parser._reconstruct(None, constants.dialect) == ""
    assert_raises(exceptions.AttributeStringError, parser._reconstruct,
                  dict(ID='asdf'), None)
    assert_raises(exceptions.AttributeStringError, parser._reconstruct, None,
                  None)
예제 #5
0
def attrs_OK(attr_str, attr_dict, acceptable_reconstruction=None):
    """
    Given an attribute string and a dictionary of what you expect, test the
    attribute splitting and reconstruction (invariant roundtrip).

    There are some corner cases for the roundtrip invariance that don't work
    (see attr_test_cases.py for details); `acceptable_reconstruction` handles
    those.
    """
    result, dialect = parser._split_keyvals(attr_str)
    assert result == attr_dict, result

    reconstructed = parser._reconstruct(result, dialect, keep_order=True)
    if acceptable_reconstruction:
        assert reconstructed == acceptable_reconstruction, reconstructed
    else:
        assert reconstructed == attr_str, reconstructed
예제 #6
0
def attrs_OK(attr_str, attr_dict, acceptable_reconstruction=None):
    """
    Given an attribute string and a dictionary of what you expect, test the
    attribute splitting and reconstruction (invariant roundtrip).

    There are some corner cases for the roundtrip invariance that don't work
    (see attr_test_cases.py for details); `acceptable_reconstruction` handles
    those.
    """
    result, dialect = parser._split_keyvals(attr_str)
    assert result == attr_dict, result

    reconstructed = parser._reconstruct(result, dialect, keep_order=True)
    if acceptable_reconstruction:
        assert reconstructed == acceptable_reconstruction, reconstructed
    else:
        assert reconstructed == attr_str, reconstructed