import argparse import os import shutil import tempfile import unittest from osc.commandline import Command from osc.commandline import MainCommand from osc.commandline import OscMainCommand from osc.commandline import pop_project_package_from_args from osc.commandline import pop_project_package_repository_arch_from_args from osc.commandline import pop_project_package_targetproject_targetpackage_from_args from osc.commandline import pop_repository_arch_from_args from osc.oscerr import NoWorkingCopy, OscValueError from osc.store import Store class TestMainCommand(MainCommand): name = "osc-test" def init_arguments(self, command=None): self.add_argument( "-A", "--apiurl", ) class TestCommand(Command): name = "test-cmd" OSCRC_LOCALHOST = """ [general] apiurl = https://localhost [https://localhost] user=Admin pass=opensuse """.lstrip() class TestCommandClasses(unittest.TestCase): def setUp(self): os.environ.pop("OSC_CONFIG", None) self.tmpdir = tempfile.mkdtemp(prefix="osc_test") os.chdir(self.tmpdir) self.oscrc = None def tearDown(self): os.environ.pop("OSC_CONFIG", None) try: shutil.rmtree(self.tmpdir) except OSError: pass def write_oscrc_localhost(self): self.oscrc = os.path.join(self.tmpdir, "oscrc") with open(self.oscrc, "w") as f: f.write(OSCRC_LOCALHOST) def test_load_commands(self): main = TestMainCommand() main.load_commands() def test_load_command(self): main = TestMainCommand() cmd = main.load_command(TestCommand, "test.osc.commands") self.assertTrue(str(cmd).startswith("