Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
converse.js
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
converse.js
Commits
899ebf1e
Commit
899ebf1e
authored
Feb 14, 2016
by
Michal Čihař
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix file format tests for Python 3
Signed-off-by:
Michal Čihař
<
michal@cihar.com
>
parent
b99dd264
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
15 deletions
+23
-15
weblate/trans/formats.py
weblate/trans/formats.py
+2
-2
weblate/trans/tests/test_formats.py
weblate/trans/tests/test_formats.py
+21
-13
No files found.
weblate/trans/formats.py
View file @
899ebf1e
...
...
@@ -727,7 +727,7 @@ class FileFormat(object):
if
cls
.
new_translation
is
None
:
raise
ValueError
(
'Not supported'
)
with
open
(
filename
,
'w
b
'
)
as
output
:
with
open
(
filename
,
'w'
)
as
output
:
output
.
write
(
cls
.
new_translation
)
def
iterate_merge
(
self
,
fuzzy
):
...
...
@@ -1175,7 +1175,7 @@ class JSONFormat(FileFormat):
@
classmethod
def
create_new_file
(
cls
,
filename
,
code
,
base
):
"""Handles creation of new translation file."""
content
=
'{}
\
n
'
content
=
b
'{}
\
n
'
if
base
:
with
open
(
base
,
'rb'
)
as
handle
:
content
=
handle
.
read
()
...
...
weblate/trans/tests/test_formats.py
View file @
899ebf1e
...
...
@@ -22,13 +22,15 @@ File format specific behavior.
'''
from
__future__
import
unicode_literals
from
io
import
BytesIO
import
io
import
tempfile
from
unittest
import
TestCase
,
SkipTest
from
six
import
StringIO
from
django.test
import
SimpleTestCase
from
django.utils.encoding
import
force_text
import
six
from
translate.storage.po
import
pofile
...
...
@@ -54,7 +56,7 @@ TEST_TS = get_test_file('cs.ts')
class
AutoLoadTest
(
TestCase
):
def
single_test
(
self
,
filename
,
fileclass
):
with
open
(
filename
,
'r'
)
as
handle
:
with
open
(
filename
,
'r
b
'
)
as
handle
:
store
=
AutoFormat
.
parse
(
handle
)
self
.
assertIsInstance
(
store
,
fileclass
)
...
...
@@ -83,10 +85,10 @@ class AutoLoadTest(TestCase):
def
test_content
(
self
):
"""Test content based guess from ttkit"""
with
open
(
TEST_PO
,
'r'
)
as
handle
:
with
open
(
TEST_PO
,
'r
b
'
)
as
handle
:
data
=
handle
.
read
()
handle
=
String
IO
(
data
)
handle
=
Bytes
IO
(
data
)
store
=
AutoFormat
.
parse
(
handle
)
self
.
assertIsInstance
(
store
,
AutoFormat
)
self
.
assertIsInstance
(
store
.
store
,
pofile
)
...
...
@@ -113,13 +115,13 @@ class AutoFormatTest(SimpleTestCase):
def
test_save
(
self
):
# Read test content
with
open
(
self
.
FILE
,
'r'
)
as
handle
:
with
open
(
self
.
FILE
,
'r
b
'
)
as
handle
:
testdata
=
handle
.
read
()
# Create test file
testfile
=
tempfile
.
NamedTemporaryFile
(
suffix
=
'.{0}'
.
format
(
self
.
EXT
),
mode
=
'w+'
mode
=
'w
b
+'
)
try
:
# Write test data to file
...
...
@@ -133,11 +135,14 @@ class AutoFormatTest(SimpleTestCase):
storage
.
save
()
# Read new content
with
open
(
testfile
.
name
,
'r'
)
as
handle
:
with
open
(
testfile
.
name
,
'r
b
'
)
as
handle
:
newdata
=
handle
.
read
()
# Check if content matches
self
.
assert_same
(
newdata
,
testdata
)
self
.
assert_same
(
force_text
(
newdata
),
force_text
(
testdata
)
)
finally
:
testfile
.
close
()
...
...
@@ -297,10 +302,13 @@ class TSFormatTest(XMLMixin, AutoFormatTest):
def
assert_same
(
self
,
newdata
,
testdata
):
# Comparing of XML with doctype fails...
self
.
assertXMLEqual
(
newdata
.
replace
(
b'<!DOCTYPE TS>'
,
b''
),
testdata
.
replace
(
b'<!DOCTYPE TS>'
,
b''
)
)
newdata
=
newdata
.
replace
(
'<!DOCTYPE TS>'
,
''
)
testdata
=
testdata
.
replace
(
'<!DOCTYPE TS>'
,
''
)
# Magic for Python 2.x
if
six
.
PY2
:
testdata
=
testdata
.
encode
(
'utf-8'
)
newdata
=
newdata
.
encode
(
'utf-8'
)
super
(
TSFormatTest
,
self
).
assert_same
(
newdata
,
testdata
)
class
OutputTest
(
TestCase
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment