<commit_before># -*- encoding: utf8 -*-
#
# The Qubes OS Project, http://www.qubes-os.org
#
# Copyright (C) 2017 <NAME>
#                               <<EMAIL>>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License along
# with this program; if not, see <http://www.gnu.org/licenses/>.

import qubesadmin.tests
import qubesadmin.tests.tools
import qubesadmin.tools.qvm_pool


class TC_00_qvm_pool(qubesadmin.tests.QubesTestCase):
    def test_000_list(self):
        self.app.expected_calls[('dom0', 'admin.pool.List', None, None)] = \
            b'0\x00pool-file\npool-lvm\n'
        self.app.expected_calls[
            ('dom0', 'admin.pool.Info', 'pool-file', None)] = \
            b'0\x00driver=file\ndir_path=/var/lib/qubes\n'
        self.app.expected_calls[
            ('dom0', 'admin.pool.Info', 'pool-lvm', None)] = \
            b'0\x00driver=lvm\nvolume_group=qubes_dom0\nthin_pool=pool00\n'
        with qubesadmin.tests.tools.StdoutBuffer() as stdout:
            self.assertEqual(0,
                qubesadmin.tools.qvm_pool.main(['ls'], app=self.app))
        self.assertEqual(stdout.getvalue(),
            'NAME       DRIVER\n'
            'pool-file  file\n'
            'pool-lvm   lvm\n')
        self.assertAllCalled()

    def test_010_drivers(self):
        self.app.expected_calls[
            ('dom0', 'admin.pool.ListDrivers', None, None)] = \
            b'0\x00file dir_path revisions_to_keep\n' \
            b'lvm volume_group thin_pool revisions_to_keep\n'
        with qubesadmin.tests.tools.StdoutBuffer() as stdout:
            self.assertEqual(0,
                qubesadmin.tools.qvm_pool.main(['drivers'], app=self.app))
        self.assertEqual(stdout.getvalue(),
            'DRIVER  OPTIONS\n'
            'file    dir_path, revisions_to_keep\n'
            'lvm     volume_group, thin_pool, revisions_to_keep\n'
        )
        self.assertAllCalled()

    def test_020_add(self):
        self.app.expected_calls[
            ('dom0', 'admin.pool.Add', 'file',
            b'name=test-pool\ndir_path=/some/path\n')] = b'0\x00'
        self.assertEqual(0,
            qubesadmin.tools.qvm_pool.main(
                ['add', 'test-pool', 'file', '-o', 'dir_path=/some/path'],
                app=self.app))
        self.assertAllCalled()

    def test_030_remove(self):
        self.app.expected_calls[
            ('dom0', 'admin.pool.Remove', 'test-pool', None)] = b'0\x00'
        self.assertEqual(0,
            qubesadmin.tools.qvm_pool.main(['rm', 'test-pool'],
                app=self.app))
        self.assertAllCalled()

    def test_040_info(self):
        self.app.expected_calls[('dom0', 'admin.pool.List', None, None)] = \
            b'0\x00pool-file\npool-lvm\n'
        self.app.expected_calls[
            ('dom0', 'admin.pool.Info', 'pool-lvm', None)] = \
            b'0\x00driver=lvm\nvolume_group=qubes_dom0\nthin_pool=pool00\n'
        with qubesadmin.tests.tools.StdoutBuffer() as stdout:
            self.assertEqual(0,
                qubesadmin.tools.qvm_pool.main(['i', 'pool-lvm'],
                    app=self.app))
        self.assertEqual(stdout.getvalue(),
            'name          pool-lvm\n'
            'driver        lvm\n'
            'thin_pool     pool00\n'
            'volume_group  qubes_dom0\n'
            )
        self.assertAllCalled()

    def test_050_set(self):
        self.app.expected_calls[('dom0', 'admin.pool.List', None, None)] = \
            b'0\x00pool-file\npool-lvm\n'
        self.app.expected_calls[
            ('dom0', 'admin.pool.Set.revisions_to_keep', 'pool-lvm', b'2')] = \
            b'0\x00'
        self.assertEqual(0,
            qubesadmin.tools.qvm_pool.main(['s', 'pool-lvm', '-o',
                'revisions_to_keep=2'],
                app=self.app))
        self.assertAllCalled()

    def test_051_set_invalid(self):
        self.app.expected_calls[('dom0', 'admin.pool.List', None, None)] = \
            b'0\x00pool-file\npool-lvm\n'
        with self.assertRaises(SystemExit) as e:
            qubesadmin.tools.qvm_pool.main(
                ['set', 'pool-lvm', '-o', 'prop=1'],
                app=self.app)
        self.assertEqual(e.exception.code, 2)
        self.assertAllCalled()
<commit_msg>Added a new test and minor updates to others<commit_after># -*- encoding: utf8 -*-
#
# The Qubes OS Project, http://www.qubes-os.org
#
# Copyright (C) 2017 <NAME>
#                               <<EMAIL>>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License along
# with this program; if not, see <http://www.gnu.org/licenses/>.

import qubesadmin.tests
import qubesadmin.tests.tools
import qubesadmin.tools.qvm_pool


class TC_00_qvm_pool(qubesadmin.tests.QubesTestCase):
    def test_000_list(self):
        self.app.expected_calls[('dom0', 'admin.pool.List', None, None)] = \
            b'0\x00pool-file\npool-lvm\n'
        self.app.expected_calls[
            ('dom0', 'admin.pool.Info', 'pool-file', None)] = \
            b'0\x00driver=file\ndir_path=/var/lib/qubes\n'
        self.app.expected_calls[
            ('dom0', 'admin.pool.Info', 'pool-lvm', None)] = \
            b'0\x00driver=lvm\nvolume_group=qubes_dom0\nthin_pool=pool00\n'
        with qubesadmin.tests.tools.StdoutBuffer() as stdout:
            self.assertEqual(0,
                qubesadmin.tools.qvm_pool.main(['list'], app=self.app))
        self.assertEqual(stdout.getvalue(),
            'NAME       DRIVER\n'
            'pool-file  file\n'
            'pool-lvm   lvm\n')
        self.assertAllCalled()

    def test_010_drivers(self):
        self.app.expected_calls[
            ('dom0', 'admin.pool.ListDrivers', None, None)] = \
            b'0\x00file dir_path revisions_to_keep\n' \
            b'lvm volume_group thin_pool revisions_to_keep\n'
        with qubesadmin.tests.tools.StdoutBuffer() as stdout:
            self.assertEqual(0,
                qubesadmin.tools.qvm_pool.main(['drivers'], app=self.app))
        self.assertEqual(stdout.getvalue(),
            'DRIVER  OPTIONS\n'
            'file    dir_path, revisions_to_keep\n'
            'lvm     volume_group, thin_pool, revisions_to_keep\n'
        )
        self.assertAllCalled()

    def test_020_add(self):
        self.app.expected_calls[
            ('dom0', 'admin.pool.Add', 'file',
            b'name=test-pool\ndir_path=/some/path\n')] = b'0\x00'
        self.assertEqual(0,
            qubesadmin.tools.qvm_pool.main(
                ['add', 'test-pool', 'file', '-o', 'dir_path=/some/path'],
                app=self.app))
        self.assertAllCalled()

    def test_030_remove(self):
        self.app.expected_calls[
            ('dom0', 'admin.pool.Remove', 'test-pool', None)] = b'0\x00'
        self.assertEqual(0,
            qubesadmin.tools.qvm_pool.main(['remove', 'test-pool'],
                app=self.app))
        self.assertAllCalled()

    def test_031_remove_multiple(self):
        self.app.expected_calls[
            ('dom0', 'admin.pool.Remove', 'test-pool-1', None)] = b'0\x00'
        self.app.expected_calls[
            ('dom0', 'admin.pool.Remove', 'test-pool-2', None)] = b'0\x00'
        self.assertEqual(0,
            qubesadmin.tools.qvm_pool.main(
                ['remove', 'test-pool-1', 'test-pool-2'],
                app=self.app))
        self.assertAllCalled()

    def test_040_info(self):
        self.app.expected_calls[('dom0', 'admin.pool.List', None, None)] = \
            b'0\x00pool-file\npool-lvm\n'
        self.app.expected_calls[
            ('dom0', 'admin.pool.Info', 'pool-lvm', None)] = \
            b'0\x00driver=lvm\nvolume_group=qubes_dom0\nthin_pool=pool00\n'
        with qubesadmin.tests.tools.StdoutBuffer() as stdout:
            self.assertEqual(0,
                qubesadmin.tools.qvm_pool.main(['info', 'pool-lvm'],
                    app=self.app))
        self.assertEqual(stdout.getvalue(),
            'name          pool-lvm\n'
            'driver        lvm\n'
            'thin_pool     pool00\n'
            'volume_group  qubes_dom0\n'
            )
        self.assertAllCalled()

    def test_050_set(self):
        self.app.expected_calls[('dom0', 'admin.pool.List', None, None)] = \
            b'0\x00pool-file\npool-lvm\n'
        self.app.expected_calls[
            ('dom0', 'admin.pool.Set.revisions_to_keep', 'pool-lvm', b'2')] = \
            b'0\x00'
        self.assertEqual(0,
            qubesadmin.tools.qvm_pool.main(['set', 'pool-lvm', '-o',
                'revisions_to_keep=2'],
                app=self.app))
        self.assertAllCalled()

    def test_051_set_invalid(self):
        self.app.expected_calls[('dom0', 'admin.pool.List', None, None)] = \
            b'0\x00pool-file\npool-lvm\n'
        with self.assertRaises(SystemExit) as e:
            qubesadmin.tools.qvm_pool.main(
                ['set', 'pool-lvm', '-o', 'prop=1'],
                app=self.app)
        self.assertEqual(e.exception.code, 1)
        self.assertAllCalled()

{'fraction_non_alphanumeric': 0.13739390913629557, 'fraction_numerical': 0.02016974538192711, 'mean_word_length': 2.1546456692913387, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5812192', 'n_tokens_mistral': 3415, 'n_tokens_neox': 3290, 'n_words': 609}