Ejemplo n.º 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')])
Ejemplo n.º 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")])
Ejemplo n.º 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'])
Ejemplo n.º 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")
Ejemplo n.º 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")])
Ejemplo n.º 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")
Ejemplo n.º 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')
Ejemplo n.º 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')
Ejemplo n.º 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")
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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')
Ejemplo n.º 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]))
Ejemplo n.º 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"))
Ejemplo n.º 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()
Ejemplo n.º 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()
Ejemplo n.º 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]))
Ejemplo n.º 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'),
        ])
Ejemplo n.º 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)
Ejemplo n.º 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')
Ejemplo n.º 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')
Ejemplo n.º 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'),
        ])
Ejemplo n.º 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)
Ejemplo n.º 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")
Ejemplo n.º 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'))
Ejemplo n.º 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'))
Ejemplo n.º 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')
Ejemplo n.º 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)
Ejemplo n.º 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')
Ejemplo n.º 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)
Ejemplo n.º 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")
Ejemplo n.º 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'))
Ejemplo n.º 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'))
Ejemplo n.º 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)
Ejemplo n.º 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')
Ejemplo n.º 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')
Ejemplo n.º 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)
Ejemplo n.º 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')
Ejemplo n.º 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')
Ejemplo n.º 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")
Ejemplo n.º 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')
Ejemplo n.º 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)
Ejemplo n.º 43
0
 def test_show_user_config(self):
     ui._raw_main(['config'])
     output = yaml.load(self.io.getoutput())
     self.assertEqual(output['option'], 'value')
Ejemplo n.º 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)
Ejemplo n.º 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')
Ejemplo n.º 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])
Ejemplo n.º 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)
Ejemplo n.º 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])
Ejemplo n.º 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])
Ejemplo n.º 50
0
 def write_cmd(self, *args):
     ui._raw_main(['write'] + list(args), self.lib)
Ejemplo n.º 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'])
Ejemplo n.º 52
0
 def _run_main(self, args, config, func):
     self.test_cmd.func = func
     ui._raw_main(args + ['test'], StringIO(config))
Ejemplo n.º 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'))
Ejemplo n.º 54
0
 def modify(self, *args):
     with control_stdin('y'):
         ui._raw_main(['modify'] + list(args), self.lib)
Ejemplo n.º 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'))
Ejemplo n.º 56
0
 def test_plugin_command_from_pluginpath(self):
     config['pluginpath'] = [os.path.join(_common.RSRC, 'beetsplug')]
     config['plugins'] = ['test']
     ui._raw_main(['test'])
Ejemplo n.º 57
0
 def test_plugin_command_from_pluginpath(self):
     config['pluginpath'] = [_common.PLUGINPATH]
     config['plugins'] = ['test']
     ui._raw_main(['test'])
Ejemplo n.º 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')
Ejemplo n.º 59
0
 def test_plugin_command_from_pluginpath(self):
     config['pluginpath'] = [os.path.join(_common.RSRC, 'beetsplug')]
     config['plugins'] = ['test']
     ui._raw_main(['test'])
Ejemplo n.º 60
0
 def modify_inp(self, inp, *args):
     with control_stdin(inp):
         ui._raw_main(['modify'] + list(args), self.lib)