Skip to content

Check for unicode byte marks in version < 3 for phylogenetic data files. - #310

Closed
evolvedmicrobe wants to merge 1 commit into
biopython:masterfrom
evolvedmicrobe:unicodeCheck
Closed

evolvedmicrobe wants to merge 1 commit into
biopython:masterfrom
evolvedmicrobe:unicodeCheck

Conversation

@evolvedmicrobe

Copy link
Copy Markdown

Same as before, but rebased appropriately.

@peterjc

peterjc commented Apr 21, 2014

Copy link
Copy Markdown
Member

Travis points out this fails on Python 2.6 (where there are no named tuples):

======================================================================

ERROR: test_unicode_exception (test_Phylo.IOTests)

----------------------------------------------------------------------

Traceback (most recent call last):

File "/home/travis/build/biopython/biopython/Tests/test_Phylo.py", line 49, in test_unicode_exception

if var.major<3:

AttributeError: 'tuple' object has no attribute 'major'

----------------------------------------------------------------------

Use the tuple indexes explicitly instead - just follow the existing pattern. Also, make the method defintiion conditional on the Python version (otherwise it will be run on Python 3 but do nothing). e.g.

    def test_unicode_exception(self):
        var = sys.version_info
        if var.major<3:
            self.assertRaises(NewickIO.NewickError, Phylo.read,EX_NEXUS_BOM,"newick")

becomes:

    if sys.version_info[0] < 3:
        def test_unicode_exception(self):
            self.assertRaises(NewickIO.NewickError, Phylo.read,EX_NEXUS_BOM,"newick")

Further minor queries: Was there any reason for introducing yet another extension for a Newick Tree file? And why is the test tree missing a terminal semi-colon (and newline)?

What should happen on Python 3 with this file? Should it just work? If so, a matching test for parsing this would be nice.

@evolvedmicrobe

Copy link
Copy Markdown
Author

I think nwk is a reasonably standard extension used for newick files, but haven't seen a standard for that.

I added a test for the file running under 3, failing under <3

@peterjc

peterjc commented Apr 21, 2014

Copy link
Copy Markdown
Member

The test looks good, but there is no reason to define var here, just use sys.version_info[0] directly in the if statement.

Perhaps I misread the old version - but your Newick test file now seems to have two trailing semi colons (and no new line at the end).

Regarding the filename extension, it just bugged me the example above used .new, but I can find earlier precedent for using .tree elsewhere in Biopython.

@evolvedmicrobe

Copy link
Copy Markdown
Author

Yep, added the ;; after. Also, woops, looks like I had called my newick file a nexus file, both .new and .nwk are used two lines above in the code for other example files.

Will wait to see if this version passes test.

Same as before, but rebased appropriately.
@evolvedmicrobe

Copy link
Copy Markdown
Author

Alright, seems to have passed all tests, should save someone a headache.

peterjc pushed a commit that referenced this pull request Apr 21, 2014
@peterjc

peterjc commented Apr 21, 2014

Copy link
Copy Markdown
Member

Cherry-pick and applied as 94d1e54 (with additional white space changes), added thank you note in acf5c68 - thank you :)

@peterjc peterjc closed this Apr 21, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants