From 7a8cb352c95277e5ff2a1f77074b670414afaf74 Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Sat, 13 Sep 2014 15:41:45 +0200 Subject: [PATCH 1/8] tests/seeyou: Use BytesIO instead of StringIO --- tests/seeyou/test_writer.py | 107 ++++++++++++++++++------------------ 1 file changed, 52 insertions(+), 55 deletions(-) diff --git a/tests/seeyou/test_writer.py b/tests/seeyou/test_writer.py index dbf7cb1..2a09274 100644 --- a/tests/seeyou/test_writer.py +++ b/tests/seeyou/test_writer.py @@ -3,17 +3,14 @@ import pytest import datetime -try: - from StringIO import StringIO -except ImportError: - from io import StringIO +from io import BytesIO from aerofiles.seeyou import Writer, WaypointStyle, ObservationZoneStyle @pytest.fixture() def output(): - return StringIO() + return BytesIO() @pytest.fixture() @@ -49,25 +46,25 @@ def writer_with_waypoints(writer): def test_header(writer): assert writer.fp.getvalue() == \ - 'name,code,country,lat,lon,elev,style,rwdir,rwlen,freq,desc\r\n' + b'name,code,country,lat,lon,elev,style,rwdir,rwlen,freq,desc\r\n' def test_write_line(writer): - writer.fp = StringIO() + writer.fp = BytesIO() writer.write_line('line') - assert writer.fp.getvalue() == 'line\r\n' + assert writer.fp.getvalue() == b'line\r\n' def test_write_line_with_unicode(writer): - writer.fp = StringIO() + writer.fp = BytesIO() writer.write_line(u'Köln') - assert writer.fp.getvalue() == u'Köln\r\n' + assert writer.fp.getvalue() == b'K\xc3\xb6ln\r\n' def test_write_fields(writer): - writer.fp = StringIO() - writer.write_fields(['col1', 'col2', 'col3', 'bla']) - assert writer.fp.getvalue() == 'col1,col2,col3,bla\r\n' + writer.fp = BytesIO() + writer.write_fields([u'col1', u'col2', u'col3', u'bla']) + assert writer.fp.getvalue() == b'col1,col2,col3,bla\r\n' def test_write_waypoint(writer): @@ -79,8 +76,8 @@ def test_write_waypoint(writer): (6 + 24.765 / 60.), ) assert writer.fp.getvalue() == \ - 'name,code,country,lat,lon,elev,style,rwdir,rwlen,freq,desc\r\n' \ - '"Meiersberg","MEIER",DE,5107.345N,00624.765E,,1,,,,\r\n' + b'name,code,country,lat,lon,elev,style,rwdir,rwlen,freq,desc\r\n' \ + b'"Meiersberg","MEIER",DE,5107.345N,00624.765E,,1,,,,\r\n' def test_write_waypoint_with_negative_coordinates(writer): @@ -92,8 +89,8 @@ def test_write_waypoint_with_negative_coordinates(writer): longitude=-(178 + .001 / 60.), ) assert writer.fp.getvalue() == \ - 'name,code,country,lat,lon,elev,style,rwdir,rwlen,freq,desc\r\n' \ - '"Somewhere else","ABCDEF42",NZ,1232.112S,17800.001W,,1,,,,\r\n' + b'name,code,country,lat,lon,elev,style,rwdir,rwlen,freq,desc\r\n' \ + b'"Somewhere else","ABCDEF42",NZ,1232.112S,17800.001W,,1,,,,\r\n' def test_write_waypoint_with_metadata(writer): @@ -111,9 +108,9 @@ def test_write_waypoint_with_metadata(writer): 'cozy little airfield' ) assert writer.fp.getvalue() == \ - 'name,code,country,lat,lon,elev,style,rwdir,rwlen,freq,desc\r\n' \ - '"Meiersberg","MEIER",DE,5107.345N,00624.765E,146.0m,2,120,930m,' \ - '"130.125","cozy little airfield"\r\n' + b'name,code,country,lat,lon,elev,style,rwdir,rwlen,freq,desc\r\n' \ + b'"Meiersberg","MEIER",DE,5107.345N,00624.765E,146.0m,2,120,930m,' \ + b'"130.125","cozy little airfield"\r\n' def test_write_task(writer_with_waypoints): @@ -122,13 +119,13 @@ def test_write_task(writer_with_waypoints): ]) assert writer_with_waypoints.fp.getvalue() == \ - 'name,code,country,lat,lon,elev,style,rwdir,rwlen,freq,desc\r\n' \ - '"TP1","TP1",DE,5107.345N,00824.765E,,1,,,,\r\n' \ - '"TP2","TP2",NL,5007.345N,00624.765E,,1,,,,\r\n' \ - '"TP3","TP3",DE,4907.345N,00724.765E,,1,,,,\r\n' \ - '\r\n' \ - '-----Related Tasks-----\r\n' \ - '"TestTask","TP1","TP2","TP3","TP1"\r\n' + b'name,code,country,lat,lon,elev,style,rwdir,rwlen,freq,desc\r\n' \ + b'"TP1","TP1",DE,5107.345N,00824.765E,,1,,,,\r\n' \ + b'"TP2","TP2",NL,5007.345N,00624.765E,,1,,,,\r\n' \ + b'"TP3","TP3",DE,4907.345N,00724.765E,,1,,,,\r\n' \ + b'\r\n' \ + b'-----Related Tasks-----\r\n' \ + b'"TestTask","TP1","TP2","TP3","TP1"\r\n' def test_write_task_with_unknown_waypoint(writer_with_waypoints): @@ -161,15 +158,15 @@ def test_write_task_options(writer_with_waypoints): ) assert writer_with_waypoints.fp.getvalue() == \ - 'name,code,country,lat,lon,elev,style,rwdir,rwlen,freq,desc\r\n' \ - '"TP1","TP1",DE,5107.345N,00824.765E,,1,,,,\r\n' \ - '"TP2","TP2",NL,5007.345N,00624.765E,,1,,,,\r\n' \ - '"TP3","TP3",DE,4907.345N,00724.765E,,1,,,,\r\n' \ - '\r\n' \ - '-----Related Tasks-----\r\n' \ - '"TestTask","TP1","TP2","TP3","TP1"\r\n' \ - 'Options,NoStart=12:34:56,TaskTime=01:45:12,WpDis=False,' \ - 'NearDis=0.7km,NearAlt=300.0m\r\n' + b'name,code,country,lat,lon,elev,style,rwdir,rwlen,freq,desc\r\n' \ + b'"TP1","TP1",DE,5107.345N,00824.765E,,1,,,,\r\n' \ + b'"TP2","TP2",NL,5007.345N,00624.765E,,1,,,,\r\n' \ + b'"TP3","TP3",DE,4907.345N,00724.765E,,1,,,,\r\n' \ + b'\r\n' \ + b'-----Related Tasks-----\r\n' \ + b'"TestTask","TP1","TP2","TP3","TP1"\r\n' \ + b'Options,NoStart=12:34:56,TaskTime=01:45:12,WpDis=False,' \ + b'NearDis=0.7km,NearAlt=300.0m\r\n' def test_write_task_options2(writer_with_waypoints): @@ -187,15 +184,15 @@ def test_write_task_options2(writer_with_waypoints): ) assert writer_with_waypoints.fp.getvalue() == \ - 'name,code,country,lat,lon,elev,style,rwdir,rwlen,freq,desc\r\n' \ - '"TP1","TP1",DE,5107.345N,00824.765E,,1,,,,\r\n' \ - '"TP2","TP2",NL,5007.345N,00624.765E,,1,,,,\r\n' \ - '"TP3","TP3",DE,4907.345N,00724.765E,,1,,,,\r\n' \ - '\r\n' \ - '-----Related Tasks-----\r\n' \ - '"TestTask","TP1","TP2","TP3","TP1"\r\n' \ - 'Options,MinDis=False,RandomOrder=False,MaxPts=5,BeforePts=1,' \ - 'AfterPts=2,Bonus=200\r\n' + b'name,code,country,lat,lon,elev,style,rwdir,rwlen,freq,desc\r\n' \ + b'"TP1","TP1",DE,5107.345N,00824.765E,,1,,,,\r\n' \ + b'"TP2","TP2",NL,5007.345N,00624.765E,,1,,,,\r\n' \ + b'"TP3","TP3",DE,4907.345N,00724.765E,,1,,,,\r\n' \ + b'\r\n' \ + b'-----Related Tasks-----\r\n' \ + b'"TestTask","TP1","TP2","TP3","TP1"\r\n' \ + b'Options,MinDis=False,RandomOrder=False,MaxPts=5,BeforePts=1,' \ + b'AfterPts=2,Bonus=200\r\n' def test_write_task_options_in_waypoints_section(writer_with_waypoints): @@ -222,16 +219,16 @@ def test_write_observation_zone(writer_with_waypoints): ) assert writer_with_waypoints.fp.getvalue() == \ - 'name,code,country,lat,lon,elev,style,rwdir,rwlen,freq,desc\r\n' \ - '"TP1","TP1",DE,5107.345N,00824.765E,,1,,,,\r\n' \ - '"TP2","TP2",NL,5007.345N,00624.765E,,1,,,,\r\n' \ - '"TP3","TP3",DE,4907.345N,00724.765E,,1,,,,\r\n' \ - '\r\n' \ - '-----Related Tasks-----\r\n' \ - '"TestTask","TP1","TP2","TP3","TP1"\r\n' \ - 'ObsZone=0,Style=2,R1=400m,A1=180,Line=1\r\n' \ - 'ObsZone=1,Style=0,R1=35000m,A1=30,R2=12000m,A2=12,A12=123.4\r\n' \ - 'ObsZone=2,Style=3,R1=2000m,A1=180,Line=1\r\n' + b'name,code,country,lat,lon,elev,style,rwdir,rwlen,freq,desc\r\n' \ + b'"TP1","TP1",DE,5107.345N,00824.765E,,1,,,,\r\n' \ + b'"TP2","TP2",NL,5007.345N,00624.765E,,1,,,,\r\n' \ + b'"TP3","TP3",DE,4907.345N,00724.765E,,1,,,,\r\n' \ + b'\r\n' \ + b'-----Related Tasks-----\r\n' \ + b'"TestTask","TP1","TP2","TP3","TP1"\r\n' \ + b'ObsZone=0,Style=2,R1=400m,A1=180,Line=1\r\n' \ + b'ObsZone=1,Style=0,R1=35000m,A1=30,R2=12000m,A2=12,A12=123.4\r\n' \ + b'ObsZone=2,Style=3,R1=2000m,A1=180,Line=1\r\n' def test_write_observation_zone_in_waypoints_section(writer_with_waypoints): From b2812979b62a11779d6df6e3952373833380083e Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Sat, 13 Sep 2014 15:46:53 +0200 Subject: [PATCH 2/8] seeyou: Added encoding property to Writer class --- aerofiles/seeyou/writer.py | 5 +++-- tests/seeyou/test_writer.py | 9 ++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/aerofiles/seeyou/writer.py b/aerofiles/seeyou/writer.py index c68996e..457fadd 100644 --- a/aerofiles/seeyou/writer.py +++ b/aerofiles/seeyou/writer.py @@ -22,8 +22,9 @@ class Writer: ANGLE_FORMAT_INT = u'%d' ANGLE_FORMAT_OTHER = u'%s' - def __init__(self, fp): + def __init__(self, fp, encoding='utf-8'): self.fp = fp + self.encoding = encoding self.wps = set() self.in_task_section = False @@ -107,7 +108,7 @@ def format_timedelta(self, timedelta): return timedelta def write_line(self, line=u''): - self.fp.write(line + u'\r\n') + self.fp.write((line + u'\r\n').encode(self.encoding)) def write_fields(self, fields): self.write_line(u','.join(fields)) diff --git a/tests/seeyou/test_writer.py b/tests/seeyou/test_writer.py index 2a09274..e325534 100644 --- a/tests/seeyou/test_writer.py +++ b/tests/seeyou/test_writer.py @@ -55,12 +55,19 @@ def test_write_line(writer): assert writer.fp.getvalue() == b'line\r\n' -def test_write_line_with_unicode(writer): +def test_write_line_with_utf8(writer): writer.fp = BytesIO() writer.write_line(u'Köln') assert writer.fp.getvalue() == b'K\xc3\xb6ln\r\n' +def test_write_line_with_latin1(output): + writer = Writer(output, 'latin1') + writer.fp = BytesIO() + writer.write_line(u'Köln') + assert writer.fp.getvalue() == b'K\xf6ln\r\n' + + def test_write_fields(writer): writer.fp = BytesIO() writer.write_fields([u'col1', u'col2', u'col3', u'bla']) From c8599cc18240ca0483d3cc42104ba1d7fc1a9095 Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Sat, 13 Sep 2014 15:41:52 +0200 Subject: [PATCH 3/8] tests/xcsoar: Use BytesIO instead of StringIO --- tests/xcsoar/test_writer.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/tests/xcsoar/test_writer.py b/tests/xcsoar/test_writer.py index 4a5f42b..d26fd1d 100644 --- a/tests/xcsoar/test_writer.py +++ b/tests/xcsoar/test_writer.py @@ -1,12 +1,11 @@ +# -*- coding: utf-8 -*- + import pytest import os.path import datetime -try: - from StringIO import StringIO -except ImportError: - from io import StringIO +from io import BytesIO from aerofiles.xcsoar import ( Writer, TaskType, PointType, ObservationZoneType, AltitudeReference @@ -17,7 +16,7 @@ @pytest.fixture() def output(): - return StringIO() + return BytesIO() @pytest.fixture() @@ -27,7 +26,7 @@ def writer(output): def read_file(filename): path = os.path.join(FOLDER, 'data', filename) - return open(path).read() + return open(path, 'rb').read() def test_write_sample_task(writer): From ac2dcf4cac54923dcd8e5fa6b902cfa0e4161f22 Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Sat, 13 Sep 2014 15:53:14 +0200 Subject: [PATCH 4/8] xcsoar: Added encoding property to Writer class --- aerofiles/xcsoar/writer.py | 5 +++-- tests/xcsoar/test_writer.py | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/aerofiles/xcsoar/writer.py b/aerofiles/xcsoar/writer.py index 79777b2..c04f3f8 100644 --- a/aerofiles/xcsoar/writer.py +++ b/aerofiles/xcsoar/writer.py @@ -16,13 +16,14 @@ class Writer: :meth:`~aerofiles.xcsoar.Writer.write_task` method. """ - def __init__(self, fp=None): + def __init__(self, fp, encoding='utf-8'): self.fp = fp + self.encoding = encoding self.indent_level = 0 def write_line(self, line): indent = '\t' * self.indent_level - self.fp.write(indent + line + '\n') + self.fp.write((indent + line + '\n').encode(self.encoding)) def format_tag_content(self, _name, **kw): params = list(map(lambda item: '%s="%s"' % item, kw.items())) diff --git a/tests/xcsoar/test_writer.py b/tests/xcsoar/test_writer.py index d26fd1d..a771cfe 100644 --- a/tests/xcsoar/test_writer.py +++ b/tests/xcsoar/test_writer.py @@ -29,6 +29,22 @@ def read_file(filename): return open(path, 'rb').read() +def test_write_line(writer): + writer.write_line('line') + assert writer.fp.getvalue() == b'line\n' + + +def test_write_line_with_utf8(writer): + writer.write_line(u'Köln') + assert writer.fp.getvalue() == b'K\xc3\xb6ln\n' + + +def test_write_line_with_latin1(output): + writer = Writer(output, 'latin1') + writer.write_line(u'Köln') + assert writer.fp.getvalue() == b'K\xf6ln\n' + + def test_write_sample_task(writer): with writer.write_task( start_max_height_ref=AltitudeReference.AGL, From a7b50dcf41974db7947a33e2f867a8c000d68f3e Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Sat, 13 Sep 2014 15:43:51 +0200 Subject: [PATCH 5/8] tests/igc: Use BytesIO instead of StringIO --- tests/igc/test_writer.py | 315 ++++++++++++++++++++------------------- 1 file changed, 160 insertions(+), 155 deletions(-) diff --git a/tests/igc/test_writer.py b/tests/igc/test_writer.py index 8ae1597..4efb688 100644 --- a/tests/igc/test_writer.py +++ b/tests/igc/test_writer.py @@ -3,17 +3,14 @@ import datetime -try: - from StringIO import StringIO -except ImportError: - from io import StringIO +from io import BytesIO from aerofiles.igc import Writer @pytest.fixture() def output(): - return StringIO() + return BytesIO() @pytest.fixture() @@ -23,7 +20,7 @@ def writer(output): def test_write_line(writer): writer.write_line('line') - assert writer.fp.getvalue() == 'line\r\n' + assert writer.fp.getvalue() == b'line\r\n' @pytest.fixture(params=['XXX', 'GCS', 'FIL', 'FLA']) @@ -39,13 +36,13 @@ def logger_id(request): def test_logger_id(writer, manufacturer_code, logger_id): writer.write_logger_id(manufacturer_code, logger_id) assert writer.fp.getvalue() == \ - 'A%s%s\r\n' % (manufacturer_code, logger_id) + ('A%s%s\r\n' % (manufacturer_code, logger_id)).encode('utf-8') def test_logger_id_with_extension(writer, manufacturer_code, logger_id): writer.write_logger_id(manufacturer_code, logger_id, 'FLIGHT:1') assert writer.fp.getvalue() == \ - 'A%s%sFLIGHT:1\r\n' % (manufacturer_code, logger_id) + ('A%s%sFLIGHT:1\r\n' % (manufacturer_code, logger_id)).encode('utf-8') def test_logger_id_with_invalid_manufacturer_code(writer): @@ -60,7 +57,7 @@ def test_logger_id_with_invalid_logger_id(writer): def test_logger_id_without_validation(writer): writer.write_logger_id('a4%', '12345', validate=False) - assert writer.fp.getvalue() == 'Aa4%12345\r\n' + assert writer.fp.getvalue() == b'Aa4%12345\r\n' def test_invalid_header_source(writer): @@ -77,7 +74,8 @@ def date(request): def test_date(writer, date): writer.write_date(date) - assert writer.fp.getvalue() == date.strftime('HFDTE%d%m%y\r\n') + assert writer.fp.getvalue() == \ + date.strftime('HFDTE%d%m%y\r\n').encode('utf-8') def test_invalid_date(writer): @@ -94,12 +92,13 @@ def fix_accuracy(request): def test_fix_accuracy(writer, fix_accuracy): writer.write_fix_accuracy(fix_accuracy) - assert writer.fp.getvalue() == 'HFFXA%03d\r\n' % fix_accuracy + assert writer.fp.getvalue() == \ + ('HFFXA%03d\r\n' % fix_accuracy).encode('utf-8') def test_default_fix_accuracy(writer): writer.write_fix_accuracy() - assert writer.fp.getvalue() == 'HFFXA500\r\n' + assert writer.fp.getvalue() == b'HFFXA500\r\n' def test_invalid_fix_accuracy(writer): @@ -121,12 +120,14 @@ def pilot(request): def test_pilot(writer, pilot): writer.write_pilot(pilot) - assert writer.fp.getvalue() == 'HFPLTPILOTINCHARGE:%s\r\n' % pilot + assert writer.fp.getvalue() == \ + ('HFPLTPILOTINCHARGE:%s\r\n' % pilot).encode('utf-8') def test_copilot(writer, pilot): writer.write_copilot(pilot) - assert writer.fp.getvalue() == 'HFCM2CREW2:%s\r\n' % pilot + assert writer.fp.getvalue() == \ + ('HFCM2CREW2:%s\r\n' % pilot).encode('utf-8') @pytest.fixture(params=['Hornet', 'JS1', 'ASW-22 BLE']) @@ -136,7 +137,8 @@ def glider_type(request): def test_glider_type(writer, glider_type): writer.write_glider_type(glider_type) - assert writer.fp.getvalue() == 'HFGTYGLIDERTYPE:%s\r\n' % glider_type + assert writer.fp.getvalue() == \ + ('HFGTYGLIDERTYPE:%s\r\n' % glider_type).encode('utf-8') @pytest.fixture(params=['D-4449', 'N116EL', '2648']) @@ -146,17 +148,18 @@ def glider_id(request): def test_glider_id(writer, glider_id): writer.write_glider_id(glider_id) - assert writer.fp.getvalue() == 'HFGIDGLIDERID:%s\r\n' % glider_id + assert writer.fp.getvalue() == \ + ('HFGIDGLIDERID:%s\r\n' % glider_id).encode('utf-8') def test_gps_datum(writer): writer.write_gps_datum(33, 'Guam-1963') - assert writer.fp.getvalue() == 'HFDTM033GPSDATUM:Guam-1963\r\n' + assert writer.fp.getvalue() == b'HFDTM033GPSDATUM:Guam-1963\r\n' def test_default_gps_datum(writer): writer.write_gps_datum() - assert writer.fp.getvalue() == 'HFDTM100GPSDATUM:WGS-1984\r\n' + assert writer.fp.getvalue() == b'HFDTM100GPSDATUM:WGS-1984\r\n' @pytest.fixture(params=['6.4', 'Flarm-IGC05.09']) @@ -167,7 +170,7 @@ def firmware_version(request): def test_firmware_version(writer, firmware_version): writer.write_firmware_version(firmware_version) assert writer.fp.getvalue() == \ - 'HFRFWFIRMWAREVERSION:%s\r\n' % firmware_version + ('HFRFWFIRMWAREVERSION:%s\r\n' % firmware_version).encode('utf-8') @pytest.fixture(params=['1.2', 'Flarm-IGC06']) @@ -178,7 +181,7 @@ def hardware_version(request): def test_hardware_version(writer, hardware_version): writer.write_hardware_version(hardware_version) assert writer.fp.getvalue() == \ - 'HFRHWHARDWAREVERSION:%s\r\n' % hardware_version + ('HFRHWHARDWAREVERSION:%s\r\n' % hardware_version).encode('utf-8') @pytest.fixture(params=[ @@ -193,7 +196,8 @@ def logger_type(request): def test_logger_type(writer, logger_type): writer.write_logger_type(logger_type) - assert writer.fp.getvalue() == 'HFFTYFRTYPE:%s\r\n' % logger_type + assert writer.fp.getvalue() == \ + ('HFFTYFRTYPE:%s\r\n' % logger_type).encode('utf-8') @pytest.fixture(params=[ @@ -208,7 +212,8 @@ def gps_receiver(request): def test_gps_receiver(writer, gps_receiver): writer.write_gps_receiver(gps_receiver) - assert writer.fp.getvalue() == 'HFGPS%s\r\n' % gps_receiver + assert writer.fp.getvalue() == \ + ('HFGPS%s\r\n' % gps_receiver).encode('utf-8') @pytest.fixture(params=[ @@ -222,7 +227,7 @@ def pressure_sensor(request): def test_pressure_sensor(writer, pressure_sensor): writer.write_pressure_sensor(pressure_sensor) assert writer.fp.getvalue() == \ - 'HFPRSPRESSALTSENSOR:%s\r\n' % pressure_sensor + ('HFPRSPRESSALTSENSOR:%s\r\n' % pressure_sensor).encode('utf-8') @pytest.fixture(params=['TH', '6H', '37', 'B', 'FUN']) @@ -233,7 +238,7 @@ def competition_id(request): def test_competition_id(writer, competition_id): writer.write_competition_id(competition_id) assert writer.fp.getvalue() == \ - 'HFCIDCOMPETITIONID:%s\r\n' % competition_id + ('HFCIDCOMPETITIONID:%s\r\n' % competition_id).encode('utf-8') @pytest.fixture(params=['Std', 'CLUB', '15M', 'Open']) @@ -244,7 +249,7 @@ def competition_class(request): def test_competition_class(writer, competition_class): writer.write_competition_class(competition_class) assert writer.fp.getvalue() == \ - 'HFCCLCOMPETITIONCLASS:%s\r\n' % competition_class + ('HFCCLCOMPETITIONCLASS:%s\r\n' % competition_class).encode('utf-8') @pytest.fixture(params=['SFN', 'LV Aachen']) @@ -255,7 +260,7 @@ def club(request): def test_club(writer, club): writer.write_club(club) assert writer.fp.getvalue() == \ - 'HFCLBCLUB:%s\r\n' % club + ('HFCLBCLUB:%s\r\n' % club).encode('utf-8') def test_headers(writer): @@ -278,24 +283,24 @@ def test_headers(writer): 'club': 'LV Aachen', }) - assert writer.fp.getvalue() == '\r\n'.join([ - 'AXCSTBX', - 'HFDTE240287', - 'HFFXA050', - 'HFPLTPILOTINCHARGE:Tobias Bieniek', - 'HFCM2CREW2:John Doe', - 'HFGTYGLIDERTYPE:Duo Discus', - 'HFGIDGLIDERID:D-KKHH', - 'HFDTM100GPSDATUM:WGS-1984', - 'HFRFWFIRMWAREVERSION:2.2', - 'HFRHWHARDWAREVERSION:2', - 'HFFTYFRTYPE:LXNAVIGATION,LX8000F', - 'HFGPSuBLOX LEA-4S-2,16,max9000m', - 'HFPRSPRESSALTSENSOR:INTERSEMA,MS5534A,max10000m', - 'HFCIDCOMPETITIONID:2H', - 'HFCCLCOMPETITIONCLASS:Doubleseater', - 'HFCLBCLUB:LV Aachen', - ]) + '\r\n' + assert writer.fp.getvalue() == b'\r\n'.join([ + b'AXCSTBX', + b'HFDTE240287', + b'HFFXA050', + b'HFPLTPILOTINCHARGE:Tobias Bieniek', + b'HFCM2CREW2:John Doe', + b'HFGTYGLIDERTYPE:Duo Discus', + b'HFGIDGLIDERID:D-KKHH', + b'HFDTM100GPSDATUM:WGS-1984', + b'HFRFWFIRMWAREVERSION:2.2', + b'HFRHWHARDWAREVERSION:2', + b'HFFTYFRTYPE:LXNAVIGATION,LX8000F', + b'HFGPSuBLOX LEA-4S-2,16,max9000m', + b'HFPRSPRESSALTSENSOR:INTERSEMA,MS5534A,max10000m', + b'HFCIDCOMPETITIONID:2H', + b'HFCCLCOMPETITIONCLASS:Doubleseater', + b'HFCLBCLUB:LV Aachen', + ]) + b'\r\n' def test_default_headers(writer): @@ -307,20 +312,20 @@ def test_default_headers(writer): 'gps_receiver': 'u-blox:LEA-4P,16,8191', }) - assert writer.fp.getvalue() == '\r\n'.join([ - 'AFLA6NG', - 'HFDTE010413', - 'HFFXA500', - 'HFPLTPILOTINCHARGE:', - 'HFGTYGLIDERTYPE:', - 'HFGIDGLIDERID:', - 'HFDTM100GPSDATUM:WGS-1984', - 'HFRFWFIRMWAREVERSION:', - 'HFRHWHARDWAREVERSION:', - 'HFFTYFRTYPE:Flarm-IGC', - 'HFGPSu-blox:LEA-4P,16,8191', - 'HFPRSPRESSALTSENSOR:', - ]) + '\r\n' + assert writer.fp.getvalue() == b'\r\n'.join([ + b'AFLA6NG', + b'HFDTE010413', + b'HFFXA500', + b'HFPLTPILOTINCHARGE:', + b'HFGTYGLIDERTYPE:', + b'HFGIDGLIDERID:', + b'HFDTM100GPSDATUM:WGS-1984', + b'HFRFWFIRMWAREVERSION:', + b'HFRHWHARDWAREVERSION:', + b'HFFTYFRTYPE:Flarm-IGC', + b'HFGPSu-blox:LEA-4P,16,8191', + b'HFPRSPRESSALTSENSOR:', + ]) + b'\r\n' def test_missing_headers(writer): @@ -330,12 +335,12 @@ def test_missing_headers(writer): def test_fix_extensions(writer): writer.write_fix_extensions([('FXA', 3), ('SIU', 2), ('ENL', 3)]) - assert writer.fp.getvalue() == 'I033638FXA3940SIU4143ENL\r\n' + assert writer.fp.getvalue() == b'I033638FXA3940SIU4143ENL\r\n' def test_empty_fix_extensions(writer): writer.write_fix_extensions([]) - assert writer.fp.getvalue() == 'I00\r\n' + assert writer.fp.getvalue() == b'I00\r\n' def test_invalid_fix_extensions(writer): @@ -352,12 +357,12 @@ def test_invalid_fix_extensions(writer): def test_k_record_extensions(writer): writer.write_k_record_extensions([('HDT', 5)]) - assert writer.fp.getvalue() == 'J010812HDT\r\n' + assert writer.fp.getvalue() == b'J010812HDT\r\n' def test_empty_k_record_extensions(writer): writer.write_k_record_extensions([]) - assert writer.fp.getvalue() == 'J00\r\n' + assert writer.fp.getvalue() == b'J00\r\n' def test_invalid_k_record_extensions(writer): @@ -374,14 +379,14 @@ def test_task_metadata(writer): text='Some more metadata', ) assert writer.fp.getvalue() == \ - 'C130414125302140414004203Some more metadata\r\n' + b'C130414125302140414004203Some more metadata\r\n' def test_default_task_metadata(writer): with freeze_time("2012-01-14 03:21:34"): writer.write_task_metadata(turnpoints=1) - assert writer.fp.getvalue() == 'C140112032134000000000101\r\n' + assert writer.fp.getvalue() == b'C140112032134000000000101\r\n' def test_task_metadata_with_invalid_datetime(writer): @@ -416,7 +421,7 @@ def test_task_point(writer): longitude=(6 + 24.765 / 60.), text='Meiersberg', ) - assert writer.fp.getvalue() == 'C5107345N00624765EMeiersberg\r\n' + assert writer.fp.getvalue() == b'C5107345N00624765EMeiersberg\r\n' def test_task_point_with_negative_coordinates(writer): @@ -425,7 +430,7 @@ def test_task_point_with_negative_coordinates(writer): longitude=-(178 + .001 / 60.), text='TAKEOFF', ) - assert writer.fp.getvalue() == 'C1232112S17800001WTAKEOFF\r\n' + assert writer.fp.getvalue() == b'C1232112S17800001WTAKEOFF\r\n' def test_task_point_with_area(writer): @@ -439,12 +444,12 @@ def test_task_point_with_area(writer): bearing2=182.0, ) assert writer.fp.getvalue() == \ - 'C1232112S17800001W00120000032000122000182000TURN AREA\r\n' + b'C1232112S17800001W00120000032000122000182000TURN AREA\r\n' def test_default_task_point(writer): writer.write_task_point() - assert writer.fp.getvalue() == 'C0000000N00000000E\r\n' + assert writer.fp.getvalue() == b'C0000000N00000000E\r\n' def test_task_points(writer): @@ -457,14 +462,14 @@ def test_task_points(writer): (None, None, 'LANDING'), ]) - assert writer.fp.getvalue() == '\r\n'.join([ - 'C0000000N00000000ETAKEOFF', - 'C5124225N00624765ESTART', - 'C5022926N00849263ETURN 1', - 'C5035427N00702133E00000000032500000000180000TURN 2', - 'C5124225N00624765EFINISH', - 'C0000000N00000000ELANDING', - ]) + '\r\n' + assert writer.fp.getvalue() == b'\r\n'.join([ + b'C0000000N00000000ETAKEOFF', + b'C5124225N00624765ESTART', + b'C5022926N00849263ETURN 1', + b'C5035427N00702133E00000000032500000000180000TURN 2', + b'C5124225N00624765EFINISH', + b'C0000000N00000000ELANDING', + ]) + b'\r\n' def test_invalid_task_points(writer): @@ -478,26 +483,26 @@ def test_invalid_task_points(writer): def test_security(writer): writer.write_security('ABCDEFGHIJKLMNOPQRSTUVWXYZ') - assert writer.fp.getvalue() == 'GABCDEFGHIJKLMNOPQRSTUVWXYZ\r\n' + assert writer.fp.getvalue() == b'GABCDEFGHIJKLMNOPQRSTUVWXYZ\r\n' def test_long_security(writer): writer.write_security('A' * 100) - assert writer.fp.getvalue() == '\r\n'.join([ - 'G' + 'A' * 75, - 'G' + 'A' * 25, - ]) + '\r\n' + assert writer.fp.getvalue() == b'\r\n'.join([ + b'G' + b'A' * 75, + b'G' + b'A' * 25, + ]) + b'\r\n' def test_custom_long_security(writer): writer.write_security('A' * 110, bytes_per_line=25) - assert writer.fp.getvalue() == '\r\n'.join([ - 'G' + 'A' * 25, - 'G' + 'A' * 25, - 'G' + 'A' * 25, - 'G' + 'A' * 25, - 'G' + 'A' * 10, - ]) + '\r\n' + assert writer.fp.getvalue() == b'\r\n'.join([ + b'G' + b'A' * 25, + b'G' + b'A' * 25, + b'G' + b'A' * 25, + b'G' + b'A' * 25, + b'G' + b'A' * 10, + ]) + b'\r\n' def test_fix(writer): @@ -509,23 +514,23 @@ def test_fix(writer): pressure_alt=1234, gps_alt=1432, ) - assert writer.fp.getvalue() == 'B1234565124225N00624765EA0123401432\r\n' + assert writer.fp.getvalue() == b'B1234565124225N00624765EA0123401432\r\n' def test_default_fix(writer): with freeze_time("2012-01-14 03:21:34"): writer.write_fix() - assert writer.fp.getvalue() == 'B0321340000000N00000000EV0000000000\r\n' + assert writer.fp.getvalue() == b'B0321340000000N00000000EV0000000000\r\n' def test_fix_with_extensions(writer): writer.write_fix_extensions([('FXA', 3), ('SIU', 2), ('ENL', 3)]) writer.write_fix(datetime.time(2, 3, 4), extensions=['023', 13, 2]) - assert writer.fp.getvalue() == '\r\n'.join([ - 'I033638FXA3940SIU4143ENL', - 'B0203040000000N00000000EV000000000002313002', - ]) + '\r\n' + assert writer.fp.getvalue() == b'\r\n'.join([ + b'I033638FXA3940SIU4143ENL', + b'B0203040000000N00000000EV000000000002313002', + ]) + b'\r\n' def test_fix_with_missing_extensions(writer): @@ -591,24 +596,24 @@ def test_fix_with_invalid_longitude(writer): def test_event(writer): writer.write_event(datetime.time(12, 34, 56), 'PEV') - assert writer.fp.getvalue() == 'E123456PEV\r\n' + assert writer.fp.getvalue() == b'E123456PEV\r\n' def test_event_with_text(writer): writer.write_event(datetime.time(1, 2, 3), 'PEV', 'This is a test') - assert writer.fp.getvalue() == 'E010203PEVThis is a test\r\n' + assert writer.fp.getvalue() == b'E010203PEVThis is a test\r\n' def test_event_with_default_time(writer): with freeze_time("2012-01-14 03:21:34"): writer.write_event('PEV') - assert writer.fp.getvalue() == 'E032134PEV\r\n' + assert writer.fp.getvalue() == b'E032134PEV\r\n' def test_event_with_default_time_and_text(writer): with freeze_time("2012-01-14 03:21:34"): writer.write_event('PEV', 'Test') - assert writer.fp.getvalue() == 'E032134PEVTest\r\n' + assert writer.fp.getvalue() == b'E032134PEVTest\r\n' def test_event_with_invalid_arguments(writer): @@ -632,13 +637,13 @@ def test_event_with_invalid_code(writer): def test_satellites(writer): writer.write_satellites(datetime.time(12, 34, 56), [2, 52, 33, '03']) - assert writer.fp.getvalue() == 'F12345602523303\r\n' + assert writer.fp.getvalue() == b'F12345602523303\r\n' def test_satellites_with_default_time(writer): with freeze_time("2012-01-14 03:21:34"): writer.write_satellites([2, 4, 99]) - assert writer.fp.getvalue() == 'F032134020499\r\n' + assert writer.fp.getvalue() == b'F032134020499\r\n' def test_satellites_with_invalid_id(writer): @@ -664,10 +669,10 @@ def test_k_record(writer): writer.write_k_record_extensions([('FXA', 3), ('SIU', 2), ('ENL', 3)]) writer.write_k_record(datetime.time(2, 3, 4), ['023', 13, 2]) - assert writer.fp.getvalue() == '\r\n'.join([ - 'J030810FXA1112SIU1315ENL', - 'K02030402313002', - ]) + '\r\n' + assert writer.fp.getvalue() == b'\r\n'.join([ + b'J030810FXA1112SIU1315ENL', + b'K02030402313002', + ]) + b'\r\n' def test_k_record_with_default_time(writer): @@ -676,10 +681,10 @@ def test_k_record_with_default_time(writer): with freeze_time("2012-01-14 03:21:34"): writer.write_k_record(['023', 13, 2]) - assert writer.fp.getvalue() == '\r\n'.join([ - 'J030810FXA1112SIU1315ENL', - 'K03213402313002', - ]) + '\r\n' + assert writer.fp.getvalue() == b'\r\n'.join([ + b'J030810FXA1112SIU1315ENL', + b'K03213402313002', + ]) + b'\r\n' def test_k_record_with_missing_arguments(writer): @@ -717,7 +722,7 @@ def test_k_record_with_invalid_extension(writer): def test_comment(writer): writer.write_comment('PLT', 'This flight was my second 1000km attempt') assert writer.fp.getvalue() == \ - 'LPLTThis flight was my second 1000km attempt\r\n' + b'LPLTThis flight was my second 1000km attempt\r\n' def test_comment_with_invalid_source(writer): @@ -884,49 +889,49 @@ def test_igc_example(writer): bytes_per_line=51 ) - assert writer.fp.getvalue() == '\r\n'.join([ - 'AXXXABCFLIGHT:1', - 'HFDTE160709', - 'HFFXA035', - 'HFPLTPILOTINCHARGE:Bloggs Bill D', - 'HFGTYGLIDERTYPE:Schempp Ventus2cxa', - 'HFGIDGLIDERID:ABCD-1234', - 'HFDTM100GPSDATUM:WGS-1984', - 'HFRFWFIRMWAREVERSION:6.4', - 'HFRHWHARDWAREVERSION:3.0', - 'HFFTYFRTYPE:Manufacturer, Model', - 'HFGPSMarconiCanada:Superstar,12ch, max10000m', - 'HFPRSPRESSALTSENSOR:Sensyn, XYZ1111, max11000m', - 'HFCIDCOMPETITIONID:XYZ-78910', - 'HFCCLCOMPETITIONCLASS:15m Motor Glider', - 'I033638FXA3940SIU4143ENL', - 'J010812HDT', - 'C150701213841160701000102500K Tri', - 'C5111359N00101899WLasham Clubhouse', - 'C5110179N00102644WLasham Start S, Start', - 'C5209092N00255227WSarnesfield, TP1', - 'C5230147N00017612WNorman Cross, TP2', - 'C5110179N00102644WLasham Start S, Finish', - 'C5111359N00101899WLasham Clubhouse', - 'F160240040609123624221821', - 'B1602405407121N00249342WA002800042120509950', - 'E160245PEV', - 'B1602455107126N00149300WA002880042919509020', - 'B1602505107134N00149283WA002900043221009015', - 'B1602555107140N00149221WA002900043020009012', - 'F1603000609123624221821', - 'B1603005107150N00149202WA002910043225608009', - 'E160305PEV', - 'B1603055107180N00149185WA002910043521008015', - 'B1603105107212N00149174WA002930043519608024', - 'K16024800090', - 'B1602485107220N00149150WA004940043619008018', - 'B1602525107330N00149127WA004960043919508015', - 'LXXXRURITANIAN STANDARD NATIONALS DAY 1', - 'LXXXFLIGHT TIME: 4:14:25, TASK SPEED:58.48KTS', - 'GREJNGJERJKNJKRE31895478537H43982FJN9248F942389T433T', - 'GJNJK2489IERGNV3089IVJE9GO398535J3894N358954983O0934', - 'GSKTO5427FGTNUT5621WKTC6714FT8957FGMKJ134527FGTR6751', - 'GK2489IERGNV3089IVJE39GO398535J3894N358954983FTGY546', - 'G12560DJUWT28719GTAOL5628FGWNIST78154INWTOLP7815FITN', - ]) + '\r\n' + assert writer.fp.getvalue() == b'\r\n'.join([ + b'AXXXABCFLIGHT:1', + b'HFDTE160709', + b'HFFXA035', + b'HFPLTPILOTINCHARGE:Bloggs Bill D', + b'HFGTYGLIDERTYPE:Schempp Ventus2cxa', + b'HFGIDGLIDERID:ABCD-1234', + b'HFDTM100GPSDATUM:WGS-1984', + b'HFRFWFIRMWAREVERSION:6.4', + b'HFRHWHARDWAREVERSION:3.0', + b'HFFTYFRTYPE:Manufacturer, Model', + b'HFGPSMarconiCanada:Superstar,12ch, max10000m', + b'HFPRSPRESSALTSENSOR:Sensyn, XYZ1111, max11000m', + b'HFCIDCOMPETITIONID:XYZ-78910', + b'HFCCLCOMPETITIONCLASS:15m Motor Glider', + b'I033638FXA3940SIU4143ENL', + b'J010812HDT', + b'C150701213841160701000102500K Tri', + b'C5111359N00101899WLasham Clubhouse', + b'C5110179N00102644WLasham Start S, Start', + b'C5209092N00255227WSarnesfield, TP1', + b'C5230147N00017612WNorman Cross, TP2', + b'C5110179N00102644WLasham Start S, Finish', + b'C5111359N00101899WLasham Clubhouse', + b'F160240040609123624221821', + b'B1602405407121N00249342WA002800042120509950', + b'E160245PEV', + b'B1602455107126N00149300WA002880042919509020', + b'B1602505107134N00149283WA002900043221009015', + b'B1602555107140N00149221WA002900043020009012', + b'F1603000609123624221821', + b'B1603005107150N00149202WA002910043225608009', + b'E160305PEV', + b'B1603055107180N00149185WA002910043521008015', + b'B1603105107212N00149174WA002930043519608024', + b'K16024800090', + b'B1602485107220N00149150WA004940043619008018', + b'B1602525107330N00149127WA004960043919508015', + b'LXXXRURITANIAN STANDARD NATIONALS DAY 1', + b'LXXXFLIGHT TIME: 4:14:25, TASK SPEED:58.48KTS', + b'GREJNGJERJKNJKRE31895478537H43982FJN9248F942389T433T', + b'GJNJK2489IERGNV3089IVJE9GO398535J3894N358954983O0934', + b'GSKTO5427FGTNUT5621WKTC6714FT8957FGMKJ134527FGTR6751', + b'GK2489IERGNV3089IVJE39GO398535J3894N358954983FTGY546', + b'G12560DJUWT28719GTAOL5628FGWNIST78154INWTOLP7815FITN', + ]) + b'\r\n' From 5b29704249675fc194a296a064ab1e3a37f24587 Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Mon, 15 Sep 2014 19:50:37 +0200 Subject: [PATCH 6/8] igc: Encode as ASCII --- aerofiles/igc/writer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aerofiles/igc/writer.py b/aerofiles/igc/writer.py index 34412c5..7c46d5f 100644 --- a/aerofiles/igc/writer.py +++ b/aerofiles/igc/writer.py @@ -80,7 +80,7 @@ def format_longitude(self, value): value, default='00000000E', is_latitude=False) def write_line(self, line): - self.fp.write(line + '\r\n') + self.fp.write((line + u'\r\n').encode('ascii', 'replace')) def write_record(self, type, record): self.write_line(type + record) From 912d47ca52945d13ac1889308c94450400b8398b Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Sat, 13 Sep 2014 15:41:35 +0200 Subject: [PATCH 7/8] tests/flarmcfg: Use BytesIO instead of StringIO --- tests/flarmcfg/test_writer.py | 53 +++++++++++++++++------------------ 1 file changed, 26 insertions(+), 27 deletions(-) diff --git a/tests/flarmcfg/test_writer.py b/tests/flarmcfg/test_writer.py index 1bec38c..17406a2 100644 --- a/tests/flarmcfg/test_writer.py +++ b/tests/flarmcfg/test_writer.py @@ -1,16 +1,15 @@ +# -*- coding: utf-8 -*- + import pytest -try: - from StringIO import StringIO -except ImportError: - from io import StringIO +from io import BytesIO from aerofiles.flarmcfg import Writer @pytest.fixture() def output(): - return StringIO() + return BytesIO() @pytest.fixture() @@ -20,57 +19,57 @@ def writer(output): def test_write_line(writer): writer.write_line('line') - assert writer.fp.getvalue() == 'line\r\n' + assert writer.fp.getvalue() == b'line\r\n' def test_write_config(writer): writer.write_config('ID', '4B3E60') - assert writer.fp.getvalue() == '$PFLAC,S,ID,4B3E60\r\n' + assert writer.fp.getvalue() == b'$PFLAC,S,ID,4B3E60\r\n' def test_write_pilot(writer): writer.write_pilot('FTV Spandau') - assert writer.fp.getvalue() == '$PFLAC,S,PILOT,FTV Spandau\r\n' + assert writer.fp.getvalue() == b'$PFLAC,S,PILOT,FTV Spandau\r\n' def test_write_copilot(writer): writer.write_copilot('John Doe') - assert writer.fp.getvalue() == '$PFLAC,S,COPIL,John Doe\r\n' + assert writer.fp.getvalue() == b'$PFLAC,S,COPIL,John Doe\r\n' def test_write_glider_type(writer): writer.write_glider_type('Astir CS') - assert writer.fp.getvalue() == '$PFLAC,S,GLIDERTYPE,Astir CS\r\n' + assert writer.fp.getvalue() == b'$PFLAC,S,GLIDERTYPE,Astir CS\r\n' def test_write_glider_id(writer): writer.write_glider_id('D-8551') - assert writer.fp.getvalue() == '$PFLAC,S,GLIDERID,D-8551\r\n' + assert writer.fp.getvalue() == b'$PFLAC,S,GLIDERID,D-8551\r\n' def test_write_competition_id(writer): writer.write_competition_id('75') - assert writer.fp.getvalue() == '$PFLAC,S,COMPID,75\r\n' + assert writer.fp.getvalue() == b'$PFLAC,S,COMPID,75\r\n' def test_write_competition_class(writer): writer.write_competition_class('Club') - assert writer.fp.getvalue() == '$PFLAC,S,COMPCLASS,Club\r\n' + assert writer.fp.getvalue() == b'$PFLAC,S,COMPCLASS,Club\r\n' def test_write_logger_interval(writer): writer.write_logger_interval(4) - assert writer.fp.getvalue() == '$PFLAC,S,LOGINT,4\r\n' + assert writer.fp.getvalue() == b'$PFLAC,S,LOGINT,4\r\n' def test_write_task_declaration(writer): writer.write_task_declaration('My Task') - assert writer.fp.getvalue() == '$PFLAC,S,NEWTASK,My Task\r\n' + assert writer.fp.getvalue() == b'$PFLAC,S,NEWTASK,My Task\r\n' def test_write_default_task_declaration(writer): writer.write_task_declaration() - assert writer.fp.getvalue() == '$PFLAC,S,NEWTASK,\r\n' + assert writer.fp.getvalue() == b'$PFLAC,S,NEWTASK,\r\n' def test_waypoint(writer): @@ -80,7 +79,7 @@ def test_waypoint(writer): description='Meiersberg', ) assert writer.fp.getvalue() == \ - '$PFLAC,S,ADDWP,5107345N,00624765E,Meiersberg\r\n' + b'$PFLAC,S,ADDWP,5107345N,00624765E,Meiersberg\r\n' def test_waypoint_with_negative_coordinates(writer): @@ -90,12 +89,12 @@ def test_waypoint_with_negative_coordinates(writer): description='TAKEOFF', ) assert writer.fp.getvalue() == \ - '$PFLAC,S,ADDWP,1232112S,17800001W,TAKEOFF\r\n' + b'$PFLAC,S,ADDWP,1232112S,17800001W,TAKEOFF\r\n' def test_default_waypoint(writer): writer.write_waypoint() - assert writer.fp.getvalue() == '$PFLAC,S,ADDWP,0000000N,00000000E,\r\n' + assert writer.fp.getvalue() == b'$PFLAC,S,ADDWP,0000000N,00000000E,\r\n' def test_waypoints(writer): @@ -108,14 +107,14 @@ def test_waypoints(writer): (None, None, 'LANDING'), ]) - assert writer.fp.getvalue() == '\r\n'.join([ - '$PFLAC,S,ADDWP,0000000N,00000000E,TAKEOFF', - '$PFLAC,S,ADDWP,5124225N,00624765E,START', - '$PFLAC,S,ADDWP,5022926N,00849263E,TURN 1', - '$PFLAC,S,ADDWP,5035427N,00702133E,TURN 2', - '$PFLAC,S,ADDWP,5124225N,00624765E,FINISH', - '$PFLAC,S,ADDWP,0000000N,00000000E,LANDING', - ]) + '\r\n' + assert writer.fp.getvalue() == b'\r\n'.join([ + b'$PFLAC,S,ADDWP,0000000N,00000000E,TAKEOFF', + b'$PFLAC,S,ADDWP,5124225N,00624765E,START', + b'$PFLAC,S,ADDWP,5022926N,00849263E,TURN 1', + b'$PFLAC,S,ADDWP,5035427N,00702133E,TURN 2', + b'$PFLAC,S,ADDWP,5124225N,00624765E,FINISH', + b'$PFLAC,S,ADDWP,0000000N,00000000E,LANDING', + ]) + b'\r\n' def test_invalid_waypoints(writer): From e7ab2c6573d6d48218a15119184305570e208ba6 Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Mon, 15 Sep 2014 19:50:43 +0200 Subject: [PATCH 8/8] flarmcfg: Encode as ASCII --- aerofiles/flarmcfg/writer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aerofiles/flarmcfg/writer.py b/aerofiles/flarmcfg/writer.py index a834417..de05b90 100644 --- a/aerofiles/flarmcfg/writer.py +++ b/aerofiles/flarmcfg/writer.py @@ -48,7 +48,7 @@ def format_longitude(self, value): value, default='00000000E', is_latitude=False) def write_line(self, line): - self.fp.write(line + '\r\n') + self.fp.write((line + u'\r\n').encode('ascii', 'replace')) def write_config(self, key, value): self.write_line('$PFLAC,S,%s,%s' % (key, value))