~hazmat/pyjuju/rapi-delta

« back to all changes in this revision

Viewing changes to juju/hooks/tests/test_cli.py

  • Committer: Kapil Thangavelu
  • Date: 2012-09-19 20:38:44 UTC
  • mfrom: (573.1.6 rest-context)
  • Revision ID: kapil@canonical.com-20120919203844-dc2pf82ttm7xj3xs
Merged rest-context into rapi-delta.

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
from contextlib import closing
9
9
 
10
10
from twisted.internet.defer import inlineCallbacks, returnValue
11
 
import yaml
12
11
 
13
12
from juju.hooks.cli import (
14
13
    CommandLineClient, parse_log_level, parse_port_protocol)
423
422
        with closing(StringIO.StringIO()) as output:
424
423
            cli.format_smart(sample, output)
425
424
            self.assertEqual(output.getvalue(), formatted)
426
 
            self.assertEqual(sample, yaml.safe_load(output.getvalue()))
427
425
 
428
426
    def test_format_smart_v2(self):
429
 
        """Verifies smart format v2 writes correct YAML"""
 
427
        """Verifies smart format v2 writes raw strings properly"""
430
428
        self.change_environment(_JUJU_CHARM_FORMAT="2")
431
429
 
432
430
        # For each case, verify actual output serialization along with
433
431
        # roundtripping through YAML
434
432
        self.assert_smart_output(None, "")  # No newline in output for None
435
 
        self.assert_smart_output("", "''\n")
436
 
        self.assert_smart_output("A string", "A string\n")
437
 
        # Note: YAML uses b64 encoding for byte strings tagged by !!binary
438
 
        self.assert_smart_output(
439
 
            "High bytes: \xCA\xFE",
440
 
            "!!binary |\n    SGlnaCBieXRlczogyv4=\n")
441
 
        self.assert_smart_output(u"", "''\n")
442
 
        self.assert_smart_output(
443
 
            u"A unicode string (but really ascii)",
444
 
            "A unicode string (but really ascii)\n")
445
 
        # Any non-ascii Unicode will use UTF-8 encoding
446
 
        self.assert_smart_output(u"中文", "\xe4\xb8\xad\xe6\x96\x87\n")
447
 
        self.assert_smart_output({}, "{}\n")
 
433
        self.assert_smart_output("", "")
 
434
        self.assert_smart_output("A string", "A string")
 
435
        self.assert_smart_output(
 
436
            "High bytes: \xCA\xFE", "High bytes: \xca\xfe")
 
437
        self.assert_smart_output("中文", "\xe4\xb8\xad\xe6\x96\x87")
448
438
        self.assert_smart_output(
449
439
            {u"public-address": u"ec2-1-2-3-4.compute-1.amazonaws.com",
450
440
             u"foo": u"bar",
451
441
             u"configured": True},
452
442
            ("configured: true\n"
453
443
             "foo: bar\n"
454
 
             "public-address: ec2-1-2-3-4.compute-1.amazonaws.com\n"))
455
 
        self.assert_smart_output(False, "false\n")
456
 
        self.assert_smart_output(True, "true\n")
457
 
        self.assert_smart_output(0.0, "0.0\n")
458
 
        self.assert_smart_output(3.14159, "3.14159\n")
459
 
        self.assert_smart_output(6.02214178e23, "6.02214178e+23\n")
460
 
        self.assert_smart_output(0, "0\n")
461
 
        self.assert_smart_output(42, "42\n")
 
444
             "public-address: ec2-1-2-3-4.compute-1.amazonaws.com"))