Skip to content

Commit

Permalink
Unicode test for file loads #74
Browse files Browse the repository at this point in the history
  • Loading branch information
geographika committed Mar 20, 2019
1 parent df590b5 commit ef30eb7
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 5 deletions.
3 changes: 2 additions & 1 deletion mappyfile.pyproj
Expand Up @@ -10,7 +10,7 @@
<OutputPath>.</OutputPath>
<Name>mappyfile</Name>
<RootNamespace>mappyfile</RootNamespace>
<InterpreterId>MSBuild|mappyfile|$(MSBuildProjectFullPath)</InterpreterId>
<InterpreterId>MSBuild|mappyfile3|$(MSBuildProjectFullPath)</InterpreterId>
<StartupFile>tests\test_comments.py</StartupFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
Expand Down Expand Up @@ -271,6 +271,7 @@
<Content Include="tests\samples\pmapper_demo.map">
<SubType>Code</SubType>
</Content>
<Content Include="tests\samples\unicode.map" />
<Content Include="tests\sample_maps\256color_overdose.map" />
<Content Include="tests\sample_maps\256color_overdose_cmt.map" />
<Content Include="tests\sample_maps\256color_overdose_res.map" />
Expand Down
2 changes: 1 addition & 1 deletion mappyfile/parser.py
Expand Up @@ -186,7 +186,7 @@ def parse(self, text, fn=None):
Parse the Mapfile
"""

text = str(text)
text = str(text) # ensure the input is a unicode string
if self.expand_includes:
text = self.load_includes(text, fn=fn)

Expand Down
2 changes: 1 addition & 1 deletion mappyfile/utils.py
Expand Up @@ -83,7 +83,7 @@ def load(fp, expand_includes=True, include_position=False, include_comments=Fals
----------
fp: file
A file-like object
A file-like object - as with all Mapfiles this should be encoded in "utf-8"
expand_includes: boolean
Load any ``INCLUDE`` files in the MapFile
include_comments: boolean
Expand Down
23 changes: 23 additions & 0 deletions tests/samples/unicode.map
@@ -0,0 +1,23 @@
CLASS

NAME 'Enw’r stryd ddynodedig'

EXPRESSION /^Designated street.*$/

STYLE

#SYMBOL 'line'

COLOR 255 0 0#red

OPACITY 100

OUTLINECOLOR 255 0 0

WIDTH 2

END



END
12 changes: 10 additions & 2 deletions tests/test_sample_maps.py
Expand Up @@ -114,13 +114,21 @@ def test_non_ascii():
print(mappyfile.dumps(d))


def test_unicode_map():

with open('./tests/samples/unicode.map', "r", encoding="utf-8") as mf_file:
mf = mappyfile.load(mf_file)

print(mappyfile.dumps(mf))


def run_tests():
pytest.main(["tests/test_sample_maps.py"])


if __name__ == '__main__':
logging.basicConfig(level=logging.DEBUG)
logging.getLogger('mappyfile').setLevel(logging.INFO)
run_tests()
# test_includes()
# run_tests()
test_unicode_map()
print("Done!")

0 comments on commit ef30eb7

Please sign in to comment.