Пример #1
0
    def test_permissions_after_saving(self):
        tempfile = get_temp_file(self)
        assert (os.stat(tempfile).st_mode & 0o777) != 0o400

        # dump some stuff and check permission
        dump({'foo': 2}, tempfile)
        self.assertEqual((os.stat(tempfile).st_mode & 0o777), 0o400)
Пример #2
0
    def test_sanity_sequence(self):
        tempfile = get_temp_file(self)

        # dump random stuff
        numbers = [random.randint(-3, 200) for _ in range(len(string.ascii_letters))]
        original_data = dict(zip(string.ascii_letters, numbers))
        dump(original_data, tempfile)

        # load and compare
        retrieved_data = load(tempfile)
        self.assertEqual(original_data, retrieved_data)
Пример #3
0
    def test_show_ok_one_other_data_type(self):
        # create a sample file
        tempfile = get_temp_file(self)
        data = {'foo': 55}
        dump(data, tempfile)

        # show it and check
        fake_stdout = io.StringIO()
        with patch('sys.stdout', fake_stdout):
            _show(tempfile)

        result = fake_stdout.getvalue()
        self.assertEqual(result, dedent("""\
            foo: 55
        """))
Пример #4
0
    def test_show_ok_several(self):
        # create a sample file
        tempfile = get_temp_file(self)
        data = {'foo': 55, 'bar': 'bleh', 'another': 88}
        dump(data, tempfile)

        # show it and check
        fake_stdout = io.StringIO()
        with patch('sys.stdout', fake_stdout):
            _show(tempfile)

        result = fake_stdout.getvalue()
        self.assertEqual(result, dedent("""\
            another: 88
            bar: 'bleh'
            foo: 55
        """))