"Fossies" - the Fresh Open Source Software Archive

Member "node-v12.18.4-win-x86/node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/easy_xml_test.py" (14 Feb 2020, 3435 Bytes) of package /windows/www/node-v12.18.4-win-x86.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 #!/usr/bin/env python
    2 
    3 # Copyright (c) 2011 Google Inc. All rights reserved.
    4 # Use of this source code is governed by a BSD-style license that can be
    5 # found in the LICENSE file.
    6 
    7 """ Unit tests for the easy_xml.py file. """
    8 
    9 import gyp.easy_xml as easy_xml
   10 import unittest
   11 try:
   12   from cStringIO import StringIO
   13 except ImportError:
   14   from io import StringIO
   15 
   16 
   17 class TestSequenceFunctions(unittest.TestCase):
   18 
   19   def setUp(self):
   20     self.stderr = StringIO()
   21 
   22   def test_EasyXml_simple(self):
   23     self.assertEqual(
   24       easy_xml.XmlToString(['test']),
   25       '<?xml version="1.0" encoding="utf-8"?><test/>')
   26 
   27     self.assertEqual(
   28       easy_xml.XmlToString(['test'], encoding='Windows-1252'),
   29       '<?xml version="1.0" encoding="Windows-1252"?><test/>')
   30 
   31   def test_EasyXml_simple_with_attributes(self):
   32     self.assertEqual(
   33       easy_xml.XmlToString(['test2', {'a': 'value1', 'b': 'value2'}]),
   34       '<?xml version="1.0" encoding="utf-8"?><test2 a="value1" b="value2"/>')
   35 
   36   def test_EasyXml_escaping(self):
   37     original = '<test>\'"\r&\nfoo'
   38     converted = '&lt;test&gt;\'&quot;&#xD;&amp;&#xA;foo'
   39     converted_apos = converted.replace("'", '&apos;')
   40     self.assertEqual(
   41       easy_xml.XmlToString(['test3', {'a': original}, original]),
   42       '<?xml version="1.0" encoding="utf-8"?><test3 a="%s">%s</test3>' %
   43       (converted, converted_apos))
   44 
   45   def test_EasyXml_pretty(self):
   46     self.assertEqual(
   47       easy_xml.XmlToString(
   48           ['test3',
   49             ['GrandParent',
   50               ['Parent1',
   51                 ['Child']
   52               ],
   53               ['Parent2']
   54             ]
   55           ],
   56           pretty=True),
   57       '<?xml version="1.0" encoding="utf-8"?>\n'
   58       '<test3>\n'
   59       '  <GrandParent>\n'
   60       '    <Parent1>\n'
   61       '      <Child/>\n'
   62       '    </Parent1>\n'
   63       '    <Parent2/>\n'
   64       '  </GrandParent>\n'
   65       '</test3>\n')
   66 
   67 
   68   def test_EasyXml_complex(self):
   69     # We want to create:
   70     target = (
   71       '<?xml version="1.0" encoding="utf-8"?>'
   72       '<Project>'
   73         '<PropertyGroup Label="Globals">'
   74           '<ProjectGuid>{D2250C20-3A94-4FB9-AF73-11BC5B73884B}</ProjectGuid>'
   75           '<Keyword>Win32Proj</Keyword>'
   76           '<RootNamespace>automated_ui_tests</RootNamespace>'
   77         '</PropertyGroup>'
   78         '<Import Project="$(VCTargetsPath)\\Microsoft.Cpp.props"/>'
   79         '<PropertyGroup '
   80             'Condition="\'$(Configuration)|$(Platform)\'=='
   81                        '\'Debug|Win32\'" Label="Configuration">'
   82           '<ConfigurationType>Application</ConfigurationType>'
   83           '<CharacterSet>Unicode</CharacterSet>'
   84         '</PropertyGroup>'
   85       '</Project>')
   86 
   87     xml = easy_xml.XmlToString(
   88         ['Project',
   89           ['PropertyGroup', {'Label': 'Globals'},
   90             ['ProjectGuid', '{D2250C20-3A94-4FB9-AF73-11BC5B73884B}'],
   91             ['Keyword', 'Win32Proj'],
   92             ['RootNamespace', 'automated_ui_tests']
   93           ],
   94           ['Import', {'Project': '$(VCTargetsPath)\\Microsoft.Cpp.props'}],
   95           ['PropertyGroup',
   96             {'Condition': "'$(Configuration)|$(Platform)'=='Debug|Win32'",
   97              'Label': 'Configuration'},
   98             ['ConfigurationType', 'Application'],
   99             ['CharacterSet', 'Unicode']
  100           ]
  101         ])
  102     self.assertEqual(xml, target)
  103 
  104 
  105 if __name__ == '__main__':
  106   unittest.main()