From b713fff00d7c1a6c50e72f69647a6b5cbe3629dd Mon Sep 17 00:00:00 2001 From: Eric Enns Date: Sun, 26 Jun 2016 11:48:09 -0500 Subject: [PATCH 1/4] Fix off by one error, causing only first line of file to be rendered in peek. --- lib/galaxy/datatypes/data.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/galaxy/datatypes/data.py b/lib/galaxy/datatypes/data.py index 36a5b78a863..db9e82eee2b 100644 --- a/lib/galaxy/datatypes/data.py +++ b/lib/galaxy/datatypes/data.py @@ -988,7 +988,7 @@ def get_file_peek( file_name, is_multi_byte=False, WIDTH=256, LINE_COUNT=5, skip if not line_wrap: if '\n' in line: i = line.index( '\n' ) - last_line = line[i:] + last_line = line[i+1:] line = line[:i] else: last_line = '' From 997fa1577b19d9daa31768731e7cd5f4a19db1e6 Mon Sep 17 00:00:00 2001 From: Eric Enns Date: Sun, 26 Jun 2016 12:42:33 -0500 Subject: [PATCH 2/4] Fixed to only line_count not line_count + 1 lines and added in really basic test --- lib/galaxy/datatypes/data.py | 2 +- test/unit/datatypes/test_data.py | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 test/unit/datatypes/test_data.py diff --git a/lib/galaxy/datatypes/data.py b/lib/galaxy/datatypes/data.py index db9e82eee2b..e9e087c2734 100644 --- a/lib/galaxy/datatypes/data.py +++ b/lib/galaxy/datatypes/data.py @@ -970,7 +970,7 @@ def get_file_peek( file_name, is_multi_byte=False, WIDTH=256, LINE_COUNT=5, skip data_checked = False temp = open( file_name, "U" ) last_line = '' - while count <= LINE_COUNT: + while count < LINE_COUNT: line = last_line + temp.readline( WIDTH - len( last_line ) ) if line and not is_multi_byte and not data_checked: # See if we have a compressed or binary file diff --git a/test/unit/datatypes/test_data.py b/test/unit/datatypes/test_data.py new file mode 100644 index 00000000000..23c39a4c038 --- /dev/null +++ b/test/unit/datatypes/test_data.py @@ -0,0 +1,10 @@ +""" +Unit tests for base DataTypes. +.. seealso:: galaxy.datatypes.data +""" + +from galaxy.datatypes.data import get_file_peek + +def test_get_file_peek( ): + # should get the first 5 lines of the file without a trailing newline character + assert get_file_peek('test-data/1.tabular', line_wrap=False) == 'chr22\t1000\tNM_17\nchr22\t2000\tNM_18\nchr10\t2200\tNM_10\nchr10\thap\ttest\nchr10\t1200\tNM_11' From 157da746d8c5da8985d71fee578ba68dc104a11f Mon Sep 17 00:00:00 2001 From: Eric Enns Date: Sun, 26 Jun 2016 12:45:34 -0500 Subject: [PATCH 3/4] Fixed E226 --- lib/galaxy/datatypes/data.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/galaxy/datatypes/data.py b/lib/galaxy/datatypes/data.py index e9e087c2734..4e1ca4560df 100644 --- a/lib/galaxy/datatypes/data.py +++ b/lib/galaxy/datatypes/data.py @@ -988,7 +988,7 @@ def get_file_peek( file_name, is_multi_byte=False, WIDTH=256, LINE_COUNT=5, skip if not line_wrap: if '\n' in line: i = line.index( '\n' ) - last_line = line[i+1:] + last_line = line[i + 1:] line = line[:i] else: last_line = '' From a68381777df3e6c8165f5b9bdc4d4abf9bee41db Mon Sep 17 00:00:00 2001 From: Eric Enns Date: Sun, 26 Jun 2016 12:56:14 -0500 Subject: [PATCH 4/4] Fixed E302 --- test/unit/datatypes/test_data.py | 1 + 1 file changed, 1 insertion(+) diff --git a/test/unit/datatypes/test_data.py b/test/unit/datatypes/test_data.py index 23c39a4c038..5be94c88178 100644 --- a/test/unit/datatypes/test_data.py +++ b/test/unit/datatypes/test_data.py @@ -5,6 +5,7 @@ Unit tests for base DataTypes. from galaxy.datatypes.data import get_file_peek + def test_get_file_peek( ): # should get the first 5 lines of the file without a trailing newline character assert get_file_peek('test-data/1.tabular', line_wrap=False) == 'chr22\t1000\tNM_17\nchr22\t2000\tNM_18\nchr10\t2200\tNM_10\nchr10\thap\ttest\nchr10\t1200\tNM_11'