0
|
1 |
#
|
|
2 |
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
# All rights reserved.
|
|
4 |
# This component and the accompanying materials are made available
|
|
5 |
# under the terms of "Eclipse Public License v1.0"
|
|
6 |
# which accompanies this distribution, and is available
|
|
7 |
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
#
|
|
9 |
# Initial Contributors:
|
|
10 |
# Nokia Corporation - initial contribution.
|
|
11 |
#
|
|
12 |
# Contributors:
|
|
13 |
#
|
|
14 |
# Description:
|
|
15 |
#
|
|
16 |
|
|
17 |
import sys, os, unittest
|
|
18 |
|
|
19 |
ROOT_PATH = os.path.dirname(os.path.abspath(__file__))
|
|
20 |
|
|
21 |
try:
|
|
22 |
from cElementTree import ElementTree
|
|
23 |
except ImportError:
|
|
24 |
try:
|
|
25 |
from elementtree import ElementTree
|
|
26 |
except ImportError:
|
|
27 |
try:
|
|
28 |
from xml.etree import cElementTree as ElementTree
|
|
29 |
except ImportError:
|
|
30 |
from xml.etree import ElementTree
|
|
31 |
|
|
32 |
from cone.public import exceptions, plugin, api
|
|
33 |
|
|
34 |
from examplemlplugin.exampleml_reader import ExamplemlReader
|
|
35 |
from examplemlplugin.exampleml_model import Output
|
|
36 |
|
|
37 |
class TestExamplemlReader(unittest.TestCase):
|
|
38 |
|
|
39 |
NAMESPACE = ExamplemlReader.NAMESPACE
|
|
40 |
|
|
41 |
def setUp(self):
|
|
42 |
self.reader = ExamplemlReader()
|
|
43 |
|
|
44 |
def assert_read_output_equals(self, data, expected):
|
|
45 |
etree = ElementTree.fromstring(data)
|
|
46 |
output = self.reader._read_output_elem(etree)
|
|
47 |
self.assertEquals(expected, output)
|
|
48 |
|
|
49 |
def test_read_output(self):
|
|
50 |
data = """<output file="test1.txt" encoding="UTF-16">Test</output>"""
|
|
51 |
self.assert_read_output_equals(data, Output('test1.txt', 'UTF-16', 'Test'))
|
|
52 |
|
|
53 |
data = """<output file="test2.txt">Test</output>"""
|
|
54 |
self.assert_read_output_equals(data, Output('test2.txt', 'UTF-8', 'Test'))
|
|
55 |
|
|
56 |
data = """<output file="test3.txt"/>"""
|
|
57 |
self.assert_read_output_equals(data, Output('test3.txt', 'UTF-8', ''))
|
|
58 |
|
|
59 |
data = """<output/>"""
|
|
60 |
self.assertRaises(exceptions.ParseError, self.reader._read_output_elem, ElementTree.fromstring(data))
|
|
61 |
|
|
62 |
def test_read_outputs(self):
|
|
63 |
data = """<?xml version="1.0" encoding="UTF-8"?>
|
|
64 |
<printml xmlns="%s">
|
|
65 |
<output file="test1.txt" encoding="UTF-16-LE">Test 1</output>
|
|
66 |
<output file="test2.txt">Test 2</output>
|
|
67 |
<output file="test3.txt"/>
|
|
68 |
</printml>""" % self.NAMESPACE
|
|
69 |
outputs = self.reader._read_outputs(ElementTree.fromstring(data))
|
|
70 |
self.assertEquals(outputs,
|
|
71 |
[Output('test1.txt', 'UTF-16-LE', 'Test 1'),
|
|
72 |
Output('test2.txt', 'UTF-8', 'Test 2'),
|
|
73 |
Output('test3.txt', 'UTF-8', '')])
|