File size: 860 Bytes
1512437
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#! /usr/bin/env python
"""
.. autoclass:: WriteFileUtf8Command
"""

import os
from pathlib import Path


class WriteFileUtf8Command(object):

    """
    Writes text to a file, encoded in utf-8::

        ---
        # A simple test which writes to a file

        - write-file-utf8:
            hello.txt: Hello world!

        - assert-output: ""

        - assert-file-utf8:
            hello.txt: Hello world!
    """

    NAME = "write-file-utf8"

    def __init__(self, spec):
        assert len(spec) == 1
        self.path, self.contents = next(
            iter(
                spec.items()
            )
        )
        self.path = Path(self.path)

    def run(self, state, case):
        with (Path(os.getcwd())/self.path).open('w') as f:
            f.write(self.contents)
        os.environ["OUTPUT"] = ""


tags = [
    WriteFileUtf8Command
]