~maas-committers/maas/trunk

« back to all changes in this revision

Viewing changes to src/provisioningserver/dhcp/tests/test_writer.py

  • Committer: MAAS Lander
  • Author(s): Gavin Panella, Ricardo Bánffy, Blake Rouse
  • Date: 2015-12-04 21:16:18 UTC
  • mfrom: (4489.5.167 python3)
  • Revision ID: maas_lander-20151204211618-ynwsu2b3qchid1az
[r=rbanffy][bug=][author=allenap] Port MAAS to Python 3.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
 
4
4
"""Tests for `provisioningserver.dhcp.writer`."""
5
5
 
6
 
from __future__ import (
7
 
    absolute_import,
8
 
    print_function,
9
 
    unicode_literals,
10
 
    )
11
 
 
12
 
str = None
13
 
 
14
 
__metaclass__ = type
15
6
__all__ = []
16
7
 
17
8
from argparse import ArgumentParser
18
 
from io import BytesIO
 
9
import io
19
10
import os
20
11
from subprocess import (
21
12
    PIPE,
30
21
from provisioningserver.dhcp import writer
31
22
from provisioningserver.dhcp.testing.config import make_subnet_config
32
23
from provisioningserver.utils.fs import read_text_file
 
24
from provisioningserver.utils.shell import select_c_utf8_locale
33
25
from testtools.matchers import (
34
26
    ContainsAll,
35
27
    MatchesStructure,
75
67
            '--omapi-key', args.omapi_key,
76
68
            ]
77
69
 
78
 
        cmd = Popen(
79
 
            script, stdout=PIPE, env=dict(PYTHONPATH=":".join(sys.path)))
 
70
        cmd = Popen(script, stdout=PIPE, env=select_c_utf8_locale())
80
71
        output, err = cmd.communicate()
81
72
 
82
73
        self.assertEqual(0, cmd.returncode, err)
83
74
 
84
 
        self.assertThat(output, ContainsAll([
 
75
        self.assertThat(output.decode("ascii"), ContainsAll([
85
76
            args.subnet,
86
77
            args.subnet_mask,
87
78
            args.broadcast_ip,
126
117
                ip_range_high='ip-range-high'))
127
118
 
128
119
    def test_run(self):
129
 
        self.patch(sys, "stdout", BytesIO())
 
120
        stdout = io.BytesIO()
 
121
        self.patch(sys, "stdout", io.TextIOWrapper(stdout, "utf-8"))
130
122
        args = self.make_args(factory.make_ipv4_network())
131
123
 
132
124
        writer.run(args)
133
125
 
134
 
        output = sys.stdout.getvalue()
 
126
        output = stdout.getvalue()
135
127
        contains_all_params = ContainsAll([
136
128
            args.subnet,
137
129
            args.interface,
145
137
            args.ip_range_low,
146
138
            args.ip_range_high,
147
139
            ])
148
 
        self.assertThat(output, contains_all_params)
 
140
        self.assertThat(output.decode("ascii"), contains_all_params)
149
141
 
150
142
    def test_run_save_to_file(self):
151
143
        args = self.make_args()