Пример #1
0
    def test_replacements_parsed(self):
        with self.write_config_file() as config:
            config.write("replace: {'[xy]': z}")

        ui._raw_main(['test'])
        replacements = self.test_cmd.lib.replacements
        self.assertEqual(replacements, [(re.compile(ur'[xy]'), u'z')])
Пример #2
0
    def test_multiple_replacements_parsed(self):
        with self.write_config_file() as config:
            config.write("replace: {'[xy]': z, foo: bar}")

        ui._raw_main(["test"])
        replacements = self.test_cmd.lib.replacements
        self.assertEqual(replacements, [(re.compile(ur"[xy]"), u"z"), (re.compile(ur"foo"), u"bar")])
Пример #3
0
 def _run_main(self, args, config_yaml, func):
     self.test_cmd.func = func
     config_yaml = textwrap.dedent(config_yaml).strip()
     if config_yaml:
         config_data = yaml.load(config_yaml, Loader=confit.Loader)
         config.set(config_data)
     ui._raw_main(args + ['test'])
Пример #4
0
    def test_completion(self):
        # Load plugin commands
        config["pluginpath"] = [os.path.join(_common.RSRC, "beetsplug")]
        config["plugins"] = ["test"]

        test_script = os.path.join(os.path.dirname(__file__), "test_completion.sh")
        bash_completion = os.path.abspath(os.environ.get("BASH_COMPLETION_SCRIPT", "/etc/bash_completion"))

        # Tests run in bash
        cmd = os.environ.get("BEETS_TEST_SHELL", "/bin/bash --norc").split()
        if not has_program(cmd[0]):
            self.skipTest("bash not available")
        tester = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE)

        # Load bash_completion
        try:
            with open(bash_completion, "r") as bash_completion:
                tester.stdin.writelines(bash_completion)
        except IOError:
            self.skipTest("bash-completion script not found")

        # Load complection script
        self.io.install()
        ui._raw_main(["completion"])
        completion_script = self.io.getoutput()
        self.io.restore()
        tester.stdin.writelines(completion_script)

        # Load testsuite
        with open(test_script, "r") as test_script:
            tester.stdin.writelines(test_script)
        (out, err) = tester.communicate()
        if tester.returncode != 0 or out != "completion tests passed\n":
            print(out)
            self.fail("test/test_completion.sh did not execute properly")
Пример #5
0
    def test_replacements_parsed(self):
        with self.write_config_file() as config:
            config.write("replace: {'[xy]': z}")

        ui._raw_main(["test"])
        replacements = self.test_cmd.lib.replacements
        self.assertEqual(replacements, [(re.compile(r"[xy]"), b"z")])
Пример #6
0
    def test_cli_config_option(self):
        config_path = os.path.join(self.temp_dir, "config.yaml")
        with open(config_path, "w") as file:
            file.write("anoption: value")

        ui._raw_main(["--config", config_path, "test"])
        self.assertEqual(config["anoption"].get(), "value")
Пример #7
0
    def test_cli_config_option(self):
        config_path = os.path.join(self.temp_dir, 'config.yaml')
        with open(config_path, 'w') as file:
            file.write('anoption: value')

        ui._raw_main(['--config', config_path, 'test'])
        self.assertEqual(config['anoption'].get(), 'value')
Пример #8
0
    def test_paths_section_respected(self):
        with self.write_config_file() as config:
            config.write('paths: {x: y}')

        ui._raw_main(['test'])
        key, template = self.test_cmd.lib.path_formats[0]
        self.assertEqual(key, 'x')
        self.assertEqual(template.original, 'y')
Пример #9
0
    def test_paths_section_respected(self):
        with self.write_config_file() as config:
            config.write("paths: {x: y}")

        ui._raw_main(["test"])
        key, template = self.test_cmd.lib.path_formats[0]
        self.assertEqual(key, "x")
        self.assertEqual(template.original, "y")
Пример #10
0
 def test_cli_skips_calculated_tracks(self):
     ui._raw_main(['replaygain'])
     item = self.lib.items()[0]
     peak = item.rg_track_peak
     item.rg_track_gain = 0.0
     ui._raw_main(['replaygain'])
     self.assertEqual(item.rg_track_gain, 0.0)
     self.assertEqual(item.rg_track_peak, peak)
Пример #11
0
    def test_cli_config_file_loads_plugin_commands(self):
        cli_config_path = os.path.join(self.temp_dir, 'config.yaml')
        with open(cli_config_path, 'w') as file:
            file.write('pluginpath: %s\n' % _common.PLUGINPATH)
            file.write('plugins: test')

        ui._raw_main(['--config', cli_config_path, 'plugin'])
        self.assertTrue(plugins.find_plugins()[0].is_test_plugin)
Пример #12
0
    def test_paths_section_respected(self):
        with self.write_config_file() as config:
            config.write('paths: {x: y}')

        ui._raw_main(['test'])
        key, template = self.test_cmd.lib.path_formats[0]
        self.assertEqual(key, 'x')
        self.assertEqual(template.original, 'y')
Пример #13
0
 def test_config_editor_not_found(self):
     def raise_os_error(*args):
         raise OSError
     os.execlp = raise_os_error
     with self.assertRaises(ui.UserError) as user_error:
         ui._raw_main(['config', '-e'])
     self.assertIn('Could not edit configuration',
                   str(user_error.exception.args[0]))
Пример #14
0
    def test_cli_config_paths_resolve_relative_to_user_dir(self):
        cli_config_path = os.path.join(self.temp_dir, "config.yaml")
        with open(cli_config_path, "w") as file:
            file.write("library: beets.db\n")
            file.write("statefile: state")

        ui._raw_main(["--config", cli_config_path, "test"])
        self.assertEqual(config["library"].as_filename(), os.path.join(self.user_config_dir, "beets.db"))
        self.assertEqual(config["statefile"].as_filename(), os.path.join(self.user_config_dir, "state"))
Пример #15
0
 def runcli(self, *args):
     # TODO mock stdin
     with capture_stdout() as out:
         try:
             ui._raw_main(_convert_args(list(args)), self.lib)
         except ui.UserError as u:
             # TODO remove this and handle exceptions in tests
             print(u.args[0])
     return out.getvalue()
Пример #16
0
 def runcli(self, *args):
     # TODO mock stdin
     with capture_stdout() as out:
         try:
             ui._raw_main(_convert_args(list(args)), self.lib)
         except ui.UserError as u:
             # TODO remove this and handle exceptions in tests
             print(u.args[0])
     return out.getvalue()
Пример #17
0
    def test_config_editor_not_found(self):
        def raise_os_error(*args):
            raise OSError

        os.execlp = raise_os_error
        with self.assertRaises(ui.UserError) as user_error:
            ui._raw_main(['config', '-e'])
        self.assertIn('Could not edit configuration',
                      str(user_error.exception.args[0]))
Пример #18
0
    def test_multiple_replacements_parsed(self):
        with self.write_config_file() as config:
            config.write("replace: {'[xy]': z, foo: bar}")

        ui._raw_main(['test'])
        replacements = self.test_cmd.lib.replacements
        self.assertEqual(replacements, [
            (re.compile(ur'[xy]'), u'z'),
            (re.compile(ur'foo'), u'bar'),
        ])
Пример #19
0
    def test_cli_config_file_loads_plugin_commands(self):
        plugin_path = os.path.join(_common.RSRC, "beetsplug")

        cli_config_path = os.path.join(self.temp_dir, "config.yaml")
        with open(cli_config_path, "w") as file:
            file.write("pluginpath: %s\n" % plugin_path)
            file.write("plugins: test")

        ui._raw_main(["--config", cli_config_path, "plugin"])
        self.assertTrue(plugins.find_plugins()[0].is_test_plugin)
Пример #20
0
    def test_cli_config_file_overwrites_user_defaults(self):
        with open(self.user_config_path, 'w') as file:
            file.write('anoption: value')

        cli_config_path = os.path.join(self.temp_dir, 'config.yaml')
        with open(cli_config_path, 'w') as file:
            file.write('anoption: cli overwrite')

        ui._raw_main(['--config', cli_config_path, 'test'])
        self.assertEqual(config['anoption'].get(), 'cli overwrite')
Пример #21
0
    def test_cli_config_file_overwrites_user_defaults(self):
        with open(self.user_config_path, 'w') as file:
            file.write('anoption: value')

        cli_config_path = os.path.join(self.temp_dir, 'config.yaml')
        with open(cli_config_path, 'w') as file:
            file.write('anoption: cli overwrite')

        ui._raw_main(['--config', cli_config_path, 'test'])
        self.assertEqual(config['anoption'].get(), 'cli overwrite')
Пример #22
0
    def test_multiple_replacements_parsed(self):
        with self.write_config_file() as config:
            config.write("replace: {'[xy]': z, foo: bar}")

        ui._raw_main(['test'])
        replacements = self.test_cmd.lib.replacements
        self.assertEqual(replacements, [
            (re.compile(u'[xy]'), u'z'),
            (re.compile(u'foo'), u'bar'),
        ])
Пример #23
0
    def test_cli_config_file_loads_plugin_commands(self):
        plugin_path = os.path.join(_common.RSRC, 'beetsplug')

        cli_config_path = os.path.join(self.temp_dir, 'config.yaml')
        with open(cli_config_path, 'w') as file:
            file.write('pluginpath: %s\n' % plugin_path)
            file.write('plugins: test')

        ui._raw_main(['--config', cli_config_path, 'plugin'])
        self.assertTrue(plugins.find_plugins()[0].is_test_plugin)
Пример #24
0
    def test_cli_config_file_overwrites_user_defaults(self):
        with open(self.user_config_path, "w") as file:
            file.write("anoption: value")

        cli_config_path = os.path.join(self.temp_dir, "config.yaml")
        with open(cli_config_path, "w") as file:
            file.write("anoption: cli overwrite")

        ui._raw_main(["--config", cli_config_path, "test"])
        self.assertEqual(config["anoption"].get(), "cli overwrite")
Пример #25
0
    def test_cli_config_paths_resolve_relative_to_user_dir(self):
        cli_config_path = os.path.join(self.temp_dir, 'config.yaml')
        with open(cli_config_path, 'w') as file:
            file.write('library: beets.db\n')
            file.write('statefile: state')

        ui._raw_main(['--config', cli_config_path, 'test'])
        self.assertEqual(config['library'].as_filename(),
                         os.path.join(self.user_config_dir, 'beets.db'))
        self.assertEqual(config['statefile'].as_filename(),
                         os.path.join(self.user_config_dir, 'state'))
Пример #26
0
    def test_cli_config_paths_resolve_relative_to_user_dir(self):
        cli_config_path = os.path.join(self.temp_dir, 'config.yaml')
        with open(cli_config_path, 'w') as file:
            file.write('library: beets.db\n')
            file.write('statefile: state')

        ui._raw_main(['--config', cli_config_path, 'test'])
        self.assertEqual(config['library'].as_filename(),
                         os.path.join(self.user_config_dir, 'beets.db'))
        self.assertEqual(config['statefile'].as_filename(),
                         os.path.join(self.user_config_dir, 'state'))
Пример #27
0
    def test_cli_config_file_overwrites_beetsdir_defaults(self):
        os.environ['BEETSDIR'] = self.beetsdir
        env_config_path = os.path.join(self.beetsdir, 'config.yaml')
        with open(env_config_path, 'w') as file:
            file.write('anoption: value')

        cli_config_path = os.path.join(self.temp_dir, 'config.yaml')
        with open(cli_config_path, 'w') as file:
            file.write('anoption: cli overwrite')

        ui._raw_main(['--config', cli_config_path, 'test'])
        self.assertEqual(config['anoption'].get(), 'cli overwrite')
Пример #28
0
    def test_default_paths_preserved(self):
        default_formats = ui.get_path_formats()

        self._reset_config()
        with self.write_config_file() as config:
            config.write('paths: {x: y}')

        ui._raw_main(['test'])
        key, template = self.test_cmd.lib.path_formats[0]
        self.assertEqual(key, 'x')
        self.assertEqual(template.original, 'y')
        self.assertEqual(self.test_cmd.lib.path_formats[1:], default_formats)
Пример #29
0
    def test_cli_config_file_overwrites_beetsdir_defaults(self):
        os.environ['BEETSDIR'] = self.beetsdir
        env_config_path = os.path.join(self.beetsdir, 'config.yaml')
        with open(env_config_path, 'w') as file:
            file.write('anoption: value')

        cli_config_path = os.path.join(self.temp_dir, 'config.yaml')
        with open(cli_config_path, 'w') as file:
            file.write('anoption: cli overwrite')

        ui._raw_main(['--config', cli_config_path, 'test'])
        self.assertEqual(config['anoption'].get(), 'cli overwrite')
Пример #30
0
    def test_default_paths_preserved(self):
        default_formats = ui.get_path_formats()

        self._reset_config()
        with self.write_config_file() as config:
            config.write("paths: {x: y}")

        ui._raw_main(["test"])
        key, template = self.test_cmd.lib.path_formats[0]
        self.assertEqual(key, "x")
        self.assertEqual(template.original, "y")
        self.assertEqual(self.test_cmd.lib.path_formats[1:], default_formats)
Пример #31
0
    def test_cli_config_file_overwrites_beetsdir_defaults(self):
        os.environ["BEETSDIR"] = self.beetsdir
        env_config_path = os.path.join(self.beetsdir, "config.yaml")
        with open(env_config_path, "w") as file:
            file.write("anoption: value")

        cli_config_path = os.path.join(self.temp_dir, "config.yaml")
        with open(cli_config_path, "w") as file:
            file.write("anoption: cli overwrite")

        ui._raw_main(["--config", cli_config_path, "test"])
        self.assertEqual(config["anoption"].get(), "cli overwrite")
Пример #32
0
    def test_cli_config_paths_resolve_relative_to_beetsdir(self):
        os.environ['BEETSDIR'] = self.beetsdir

        cli_config_path = os.path.join(self.temp_dir, 'config.yaml')
        with open(cli_config_path, 'w') as file:
            file.write('library: beets.db\n')
            file.write('statefile: state')

        ui._raw_main(['--config', cli_config_path, 'test'])
        self.assert_equal_path(config['library'].as_filename(),
                               os.path.join(self.beetsdir, 'beets.db'))
        self.assert_equal_path(config['statefile'].as_filename(),
                               os.path.join(self.beetsdir, 'state'))
Пример #33
0
    def test_cli_config_paths_resolve_relative_to_beetsdir(self):
        os.environ['BEETSDIR'] = self.beetsdir

        cli_config_path = os.path.join(self.temp_dir, 'config.yaml')
        with open(cli_config_path, 'w') as file:
            file.write('library: beets.db\n')
            file.write('statefile: state')

        ui._raw_main(['--config', cli_config_path, 'test'])
        self.assert_equal_path(config['library'].as_filename(),
                               os.path.join(self.beetsdir, 'beets.db'))
        self.assert_equal_path(config['statefile'].as_filename(),
                               os.path.join(self.beetsdir, 'state'))
Пример #34
0
    def test_cli_saves_track_gain(self):
        for item in self.lib.items():
            self.assertEqual(item.rg_track_peak, 0.0)
            self.assertEqual(item.rg_track_gain, 0.0)
            mediafile = MediaFile(item.path)
            self.assertEqual(mediafile.rg_track_peak, 0.0)
            self.assertEqual(mediafile.rg_track_gain, 0.0)

        ui._raw_main(['replaygain'])
        for item in self.lib.items():
            self.assertNotEqual(item.rg_track_peak, 0.0)
            self.assertNotEqual(item.rg_track_gain, 0.0)
            mediafile = MediaFile(item.path)
            self.assertAlmostEqual(
                mediafile.rg_track_peak, item.rg_track_peak, places=6)
            self.assertAlmostEqual(
                mediafile.rg_track_gain, item.rg_track_gain, places=6)
Пример #35
0
    def test_completion(self):
        # Load plugin commands
        config['pluginpath'] = [os.path.join(_common.RSRC, 'beetsplug')]
        config['plugins'] = ['test']

        test_script = os.path.join(
            os.path.dirname(__file__), 'test_completion.sh'
        )
        bash_completion = os.path.abspath(os.environ.get(
            'BASH_COMPLETION_SCRIPT', '/etc/bash_completion'))

        # Tests run in bash
        shell = os.environ.get('BEETS_TEST_SHELL', '/bin/bash --norc')
        try:
            with open(os.devnull, 'wb') as devnull:
                subprocess.check_call(shell.split() + ['--version'],
                                      stdout=devnull)
        except OSError:
            self.skipTest('bash not available')
        tester = subprocess.Popen(shell.split(' '), stdin=subprocess.PIPE,
                                  stdout=subprocess.PIPE)

        # Load bash_completion
        try:
            with open(bash_completion, 'r') as bash_completion:
                tester.stdin.writelines(bash_completion)
        except IOError:
            self.skipTest('bash-completion script not found')

        # Load complection script
        self.io.install()
        ui._raw_main(['completion'])
        completion_script = self.io.getoutput()
        self.io.restore()
        tester.stdin.writelines(completion_script)
        # from beets import plugins
        # for cmd in plugins.commands():
        #     print(cmd.name)

        # Load testsuite
        with open(test_script, 'r') as test_script:
            tester.stdin.writelines(test_script)
        (out, err) = tester.communicate()
        if tester.returncode != 0 or out != "completion tests passed\n":
            print(out)
            self.fail('test/test_completion.sh did not execute properly')
Пример #36
0
    def test_completion(self):
        # Load plugin commands
        config['pluginpath'] = [os.path.join(_common.RSRC, 'beetsplug')]
        config['plugins'] = ['test']

        # Tests run in bash
        cmd = os.environ.get('BEETS_TEST_SHELL', '/bin/bash --norc').split()
        if not has_program(cmd[0]):
            self.skipTest(u'bash not available')
        tester = subprocess.Popen(cmd,
                                  stdin=subprocess.PIPE,
                                  stdout=subprocess.PIPE)

        # Load bash_completion library.
        for path in commands.BASH_COMPLETION_PATHS:
            if os.path.exists(util.syspath(path)):
                bash_completion = path
                break
        else:
            self.skipTest(u'bash-completion script not found')
        try:
            with open(util.syspath(bash_completion), 'r') as f:
                tester.stdin.writelines(f)
        except IOError:
            self.skipTest(u'could not read bash-completion script')

        # Load completion script.
        self.io.install()
        ui._raw_main(['completion'])
        completion_script = self.io.getoutput()
        self.io.restore()
        tester.stdin.writelines(completion_script)

        # Load test suite.
        test_script = os.path.join(_common.RSRC, 'test_completion.sh')
        with open(test_script, 'r') as test_script:
            tester.stdin.writelines(test_script)
        (out, err) = tester.communicate()
        if tester.returncode != 0 or out != u"completion tests passed\n":
            print(out)
            self.fail(u'test/test_completion.sh did not execute properly')
Пример #37
0
    def test_cli_saves_album_gain_to_file(self):
        for item in self.lib.items():
            mediafile = MediaFile(item.path)
            self.assertEqual(mediafile.rg_album_peak, 0.0)
            self.assertEqual(mediafile.rg_album_gain, 0.0)

        ui._raw_main(['replaygain', '-a'])

        peaks = []
        gains = []
        for item in self.lib.items():
            mediafile = MediaFile(item.path)
            peaks.append(mediafile.rg_album_peak)
            gains.append(mediafile.rg_album_gain)

        # Make sure they are all the same
        self.assertEqual(max(peaks), min(peaks))
        self.assertEqual(max(gains), min(gains))

        self.assertNotEqual(max(gains), 0.0)
        self.assertNotEqual(max(peaks), 0.0)
Пример #38
0
    def test_completion(self):
        # Load plugin commands
        config['pluginpath'] = [_common.PLUGINPATH]
        config['plugins'] = ['test']

        # Tests run in bash
        cmd = os.environ.get('BEETS_TEST_SHELL', '/bin/bash --norc').split()
        if not has_program(cmd[0]):
            self.skipTest(u'bash not available')
        tester = subprocess.Popen(cmd, stdin=subprocess.PIPE,
                                  stdout=subprocess.PIPE)

        # Load bash_completion library.
        for path in commands.BASH_COMPLETION_PATHS:
            if os.path.exists(util.syspath(path)):
                bash_completion = path
                break
        else:
            self.skipTest(u'bash-completion script not found')
        try:
            with open(util.syspath(bash_completion), 'r') as f:
                tester.stdin.writelines(f)
        except IOError:
            self.skipTest(u'could not read bash-completion script')

        # Load completion script.
        self.io.install()
        ui._raw_main(['completion'])
        completion_script = self.io.getoutput()
        self.io.restore()
        tester.stdin.writelines(completion_script)

        # Load test suite.
        test_script = os.path.join(_common.RSRC, b'test_completion.sh')
        with open(test_script, 'r') as test_script:
            tester.stdin.writelines(test_script)
        (out, err) = tester.communicate()
        if tester.returncode != 0 or out != u"completion tests passed\n":
            print(out)
            self.fail(u'test/test_completion.sh did not execute properly')
Пример #39
0
    def test_completion(self):
        # Load plugin commands
        config['pluginpath'] = [os.path.join(_common.RSRC, 'beetsplug')]
        config['plugins'] = ['test']

        test_script = os.path.join(os.path.dirname(__file__),
                                   'test_completion.sh')
        bash_completion = os.path.abspath(
            os.environ.get('BASH_COMPLETION_SCRIPT', '/etc/bash_completion'))

        # Tests run in bash
        cmd = os.environ.get('BEETS_TEST_SHELL', '/bin/bash --norc').split()
        if not has_program(cmd[0]):
            self.skipTest('bash not available')
        tester = subprocess.Popen(cmd,
                                  stdin=subprocess.PIPE,
                                  stdout=subprocess.PIPE)

        # Load bash_completion
        try:
            with open(bash_completion, 'r') as bash_completion:
                tester.stdin.writelines(bash_completion)
        except IOError:
            self.skipTest('bash-completion script not found')

        # Load complection script
        self.io.install()
        ui._raw_main(['completion'])
        completion_script = self.io.getoutput()
        self.io.restore()
        tester.stdin.writelines(completion_script)

        # Load testsuite
        with open(test_script, 'r') as test_script:
            tester.stdin.writelines(test_script)
        (out, err) = tester.communicate()
        if tester.returncode != 0 or out != "completion tests passed\n":
            print(out)
            self.fail('test/test_completion.sh did not execute properly')
Пример #40
0
    def test_completion(self):
        # Load plugin commands
        config["pluginpath"] = [os.path.join(_common.RSRC, "beetsplug")]
        config["plugins"] = ["test"]

        # Tests run in bash
        cmd = os.environ.get("BEETS_TEST_SHELL", "/bin/bash --norc").split()
        if not has_program(cmd[0]):
            self.skipTest("bash not available")
        tester = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE)

        # Load bash_completion library.
        for path in commands.BASH_COMPLETION_PATHS:
            if os.path.exists(util.syspath(path)):
                bash_completion = path
                break
        else:
            self.skipTest("bash-completion script not found")
        try:
            with open(util.syspath(bash_completion), "r") as f:
                tester.stdin.writelines(f)
        except IOError:
            self.skipTest("could not read bash-completion script")

        # Load completion script.
        self.io.install()
        ui._raw_main(["completion"])
        completion_script = self.io.getoutput()
        self.io.restore()
        tester.stdin.writelines(completion_script)

        # Load test suite.
        test_script = os.path.join(_common.RSRC, "test_completion.sh")
        with open(test_script, "r") as test_script:
            tester.stdin.writelines(test_script)
        (out, err) = tester.communicate()
        if tester.returncode != 0 or out != "completion tests passed\n":
            print(out)
            self.fail("test/test_completion.sh did not execute properly")
Пример #41
0
    def test_completion(self):
        # Load plugin commands
        config['pluginpath'] = [os.path.join(_common.RSRC, 'beetsplug')]
        config['plugins'] = ['test']

        test_script = os.path.join(os.path.dirname(__file__),
                'test_completion.sh')
        bash_completion = os.path.abspath(os.environ.get(
            'BASH_COMPLETION_SCRIPT', '/etc/bash_completion'))

        # Tests run in bash
        shell = os.environ.get('BEETS_TEST_SHELL', '/bin/bash --norc')
        tester = subprocess.Popen(shell.split(' '), stdin=subprocess.PIPE,
                                  stdout=subprocess.PIPE)

        # Load bash_completion
        with open(bash_completion, 'r') as bash_completion:
            tester.stdin.writelines(bash_completion)

        # Load complection script
        self.io.install()
        ui._raw_main(['completion'])
        completion_script = self.io.getoutput()
        self.io.restore()
        tester.stdin.writelines(completion_script)
        # from beets import plugins
        # for cmd in plugins.commands():
        #     print(cmd.name)

        # Load testsuite
        with open(test_script, 'r') as test_script:
            tester.stdin.writelines(test_script)
        (out, err) = tester.communicate()
        if tester.returncode != 0 or out != "completion tests passed\n":
            print(out)
            self.fail('test/test_completion.sh did not execute properly')
Пример #42
0
 def test_show_user_config_with_defaults(self):
     ui._raw_main(['config', '-d'])
     output = yaml.load(self.io.getoutput())
     self.assertEqual(output['option'], 'value')
     self.assertEqual(output['library'], 'lib')
     self.assertEqual(output['import']['timid'], False)
Пример #43
0
 def test_show_user_config(self):
     ui._raw_main(['config'])
     output = yaml.load(self.io.getoutput())
     self.assertEqual(output['option'], 'value')
Пример #44
0
 def test_config_paths(self):
     ui._raw_main(['config', '-p'])
     paths = self.io.getoutput().split('\n')
     self.assertEqual(len(paths), 2)
     self.assertEqual(paths[0], self.config_path)
Пример #45
0
 def test_show_user_config_with_cli(self):
     ui._raw_main(['--config', self.cli_config_path, 'config'])
     output = yaml.load(self.io.getoutput())
     self.assertEqual(output['library'], 'lib')
     self.assertEqual(output['option'], 'cli overwrite')
Пример #46
0
    def test_edit_config_with_editor_env(self):
        self.execlp_stub()
        os.environ['EDITOR'] = 'myeditor'

        ui._raw_main(['config', '-e'])
        self.assertEqual(self._execlp_call, ['myeditor', self.config_path])
Пример #47
0
 def test_config_paths_with_cli(self):
     ui._raw_main(['--config', self.cli_config_path, 'config', '-p'])
     paths = self.io.getoutput().split('\n')
     self.assertEqual(len(paths), 3)
     self.assertEqual(paths[0], self.cli_config_path)
Пример #48
0
    def test_edit_config_with_windows_exec(self):
        self.execlp_stub()

        with _common.system_mock('Windows'):
            ui._raw_main(['config', '-e'])
        self.assertEqual(self._execlp_call, [self.config_path])
Пример #49
0
    def test_edit_config_with_xdg_open(self):
        self.execlp_stub()

        with _common.system_mock('Linux'):
            ui._raw_main(['config', '-e'])
        self.assertEqual(self._execlp_call, ['xdg-open', self.config_path])
Пример #50
0
 def write_cmd(self, *args):
     ui._raw_main(['write'] + list(args), self.lib)
Пример #51
0
    def test_nonexistant_db(self):
        with self.write_config_file() as config:
            config.write('library: /xxx/yyy/not/a/real/path')

        with self.assertRaises(ui.UserError):
            ui._raw_main(['test'])
Пример #52
0
 def _run_main(self, args, config, func):
     self.test_cmd.func = func
     ui._raw_main(args + ['test'], StringIO(config))
Пример #53
0
 def test_command_line_option_relative_to_working_dir(self):
     os.chdir(self.temp_dir)
     ui._raw_main(['--library', 'foo.db', 'test'])
     self.assertEqual(config['library'].as_filename(),
                      os.path.join(os.getcwd(), 'foo.db'))
Пример #54
0
 def modify(self, *args):
     with control_stdin('y'):
         ui._raw_main(['modify'] + list(args), self.lib)
Пример #55
0
 def test_command_line_option_relative_to_working_dir(self):
     os.chdir(self.temp_dir)
     ui._raw_main(['--library', 'foo.db', 'test'])
     self.assertEqual(config['library'].as_filename(),
                      os.path.join(os.getcwd(), 'foo.db'))
Пример #56
0
 def test_plugin_command_from_pluginpath(self):
     config['pluginpath'] = [os.path.join(_common.RSRC, 'beetsplug')]
     config['plugins'] = ['test']
     ui._raw_main(['test'])
Пример #57
0
 def test_plugin_command_from_pluginpath(self):
     config['pluginpath'] = [_common.PLUGINPATH]
     config['plugins'] = ['test']
     ui._raw_main(['test'])
Пример #58
0
    def test_user_config_file(self):
        with self.write_config_file() as file:
            file.write('anoption: value')

        ui._raw_main(['test'])
        self.assertEqual(config['anoption'].get(), 'value')
Пример #59
0
 def test_plugin_command_from_pluginpath(self):
     config['pluginpath'] = [os.path.join(_common.RSRC, 'beetsplug')]
     config['plugins'] = ['test']
     ui._raw_main(['test'])
Пример #60
0
 def modify_inp(self, inp, *args):
     with control_stdin(inp):
         ui._raw_main(['modify'] + list(args), self.lib)