Ejemplo n.º 1
0
 def test_ui_log_block(self):
     old_ui = self._ui_swap()
     try:
         self.mp._ui.block()
         with capture() as out:
             self.mp._ui.log(UserInteraction.LOG_URGENT, "urgent")
             self.mp._ui.log(UserInteraction.LOG_RESULT, "result")
             self.mp._ui.log(UserInteraction.LOG_ERROR, "error")
             self.mp._ui.log(UserInteraction.LOG_NOTIFY, "notify")
             self.mp._ui.log(UserInteraction.LOG_WARNING, "warning")
             self.mp._ui.log(UserInteraction.LOG_PROGRESS, "progress")
             self.mp._ui.log(UserInteraction.LOG_DEBUG, "debug")
             self.mp._ui.log(UserInteraction.LOG_ALL, "all")
         self.assertEquals(out, ['', ''])
         with capture() as out:
             self.mp._ui.unblock()
         self.assertEquals(len(out), 2)
         self.assertEquals(out[0], '')
         # Check stripped output
         output = [x.strip() for x in out[1].split('\r')]
         self.assertEquals(output, ['urgent', 'result', 'error',
                                    'notify', 'warning', 'progress',
                                    'debug', 'all', ''])
         # Progress has \r in the end instead of \n
         progress_str = [x for x in out[1].split('\r\n')
                         if 'progress' in x][0].strip()
         self.assertEquals(progress_str,
                           ''.join(['progress', ' ' * 71, '\rdebug']))
     finally:
         self.mp._ui = old_ui
Ejemplo n.º 2
0
 def test_ui_log_block(self):
     old_ui = self._ui_swap()
     try:
         self.mp._ui.block()
         with capture() as out:
             self.mp._ui.log(UserInteraction.LOG_URGENT, "urgent")
             self.mp._ui.log(UserInteraction.LOG_RESULT, "result")
             self.mp._ui.log(UserInteraction.LOG_ERROR, "error")
             self.mp._ui.log(UserInteraction.LOG_NOTIFY, "notify")
             self.mp._ui.log(UserInteraction.LOG_WARNING, "warning")
             self.mp._ui.log(UserInteraction.LOG_PROGRESS, "progress")
             self.mp._ui.log(UserInteraction.LOG_DEBUG, "debug")
             self.mp._ui.log(UserInteraction.LOG_ALL, "all")
         self.assertEquals(out, ['', ''])
         with capture() as out:
             self.mp._ui.unblock()
         self.assertEquals(len(out), 2)
         self.assertEquals(out[0], '')
         # Check stripped output
         output = [x.strip() for x in out[1].split('\r')]
         self.assertEquals(output, ['urgent', 'result', 'error',
                                    'notify', 'warning', 'progress',
                                    'debug', 'all', ''])
         # Progress has \r in the end instead of \n
         progress_str = [x for x in out[1].split('\r\n')
                                 if 'progress' in x][0].strip()
         self.assertEquals(progress_str,
                           ''.join(['progress', ' ' * 71, '\rdebug']))
     finally:
         self.mp._ui = old_ui
Ejemplo n.º 3
0
 def test_dsn_not_provided_error(self):
     from architect.exceptions import DsnNotProvidedError
     sys.argv = [
         'architect', 'partition', '--module', 'tests.models.sqlalchemy'
     ]
     with capture() as (_, err):
         self.assertIn(str(DsnNotProvidedError()).lower(), err.lower())
Ejemplo n.º 4
0
 def setUpClass(cls):
     sys.argv = [
         'architect', 'partition', '--module', 'tests.models.peewee'
     ]
     with capture() as (out, _):
         search = 'successfully (re)configured the database for the following models'
         assert search in out, '{0} not in {1}'.format(search, out)
Ejemplo n.º 5
0
 def test_bad_dsn_provided_error(self):
     from architect.exceptions import DsnParseError
     sys.argv = [
         'architect', 'partition', '--module', 'tests.models.sqlalchemy',
         '--connection', 'foobar'
     ]
     with capture() as (_, err):
         self.assertIn(
             str(DsnParseError(current='foobar')).lower(), err.lower())
Ejemplo n.º 6
0
 def test_ui_debug_log_debug_not_set(self):
     old_ui = self._ui_swap()
     try:
         with capture() as out:
             self.mp._ui._debug_log("text", UserInteraction.LOG_ALL,
                                    prefix='testprefix')
         self.assertNotIn("testprefixlog(99): text", ''.join(out))
     finally:
         self.mp._ui = old_ui
Ejemplo n.º 7
0
 def test_ui_debug_log_debug_not_set(self):
     old_ui = self._ui_swap()
     try:
         with capture() as out:
             self.mp._ui._debug_log("text", UserInteraction.LOG_ALL,
                                    prefix='testprefix')
         self.assertNotIn("testprefixlog(99): text", ''.join(out))
     finally:
         self.mp._ui = old_ui
Ejemplo n.º 8
0
 def setUpClass(cls):
     sys.argv = [
         'architect', 'partition', '--module', 'tests.models.sqlalchemy',
         '--connection', dsn
     ]
     with capture() as (out, _):
         search = 'successfully (re)configured the database for the following models'
         assert search in out, '{0} not in {1}'.format(search, out)
     cls.session = sessionmaker(bind=engine)()
Ejemplo n.º 9
0
 def test_ui_debug_log_debug_set(self):
     old_ui = self._ui_swap()
     try:
         self.mp._ui.log_prefix = 'testprefix'
         with capture() as out:
             self.mp.set("sys.debug=log")
             self.mp._ui._debug_log("text", UserInteraction.LOG_ALL)
         self.assertIn("testprefixlog(99): text", ''.join(out))
     finally:
         self.mp._ui = old_ui
Ejemplo n.º 10
0
 def test_ui_display_result_text(self):
     old_ui = self._ui_swap()
     try:
         with capture() as out:
             self.mp._ui.render_mode = 'text'
             result = self.mp.rescan()
             self.mp._ui.display_result(result)
         self.assertEquals(out[0],
                           "{'messages': 0, 'vcards': 0, 'mailboxes': 0}\n")
     finally:
         self.mp._ui = old_ui
Ejemplo n.º 11
0
 def test_ui_display_result_text(self):
     old_ui = self._ui_swap()
     try:
         with capture() as out:
             self.mp._ui.render_mode = 'text'
             result = self.mp.rescan()
             self.mp._ui.display_result(result)
         self.assertEquals(out[0],
                           "{'messages': 0, 'vcards': 0, 'mailboxes': 0}\n")
     finally:
         self.mp._ui = old_ui
Ejemplo n.º 12
0
 def test_ui_display_result_text(self):
     old_ui = self._ui_swap()
     try:
         with capture() as out:
             self.mp._ui.render_mode = 'text'
             result = self.mp.rescan()
             self.mp._ui.display_result(result)
         self.assertEquals(out[0], ('{\n'
                                    '    "mailboxes": 0, \n'
                                    '    "messages": 0, \n'
                                    '    "vcards": 0\n'
                                    '}\n'))
     finally:
         self.mp._ui = old_ui
Ejemplo n.º 13
0
def test_fetchall():
    """ Run 'git up' with fetch.all """
    os.chdir(repo_path)

    from PyGitUp.gitup import GitUp
    gitup = GitUp(testing=True)

    with capture() as [stdout, _]:
        gitup.run()

    stdout = stdout.getvalue()

    assert_true('origin' in stdout)
    assert_true(test_name in stdout)
Ejemplo n.º 14
0
 def test_ui_display_result_text(self):
     old_ui = self._ui_swap()
     try:
         with capture() as out:
             self.mp._ui.render_mode = 'text'
             result = self.mp.rescan()
             self.mp._ui.display_result(result)
         self.assertEquals(out[0], ('{\n'
                                    '    "mailboxes": 0, \n'
                                    '    "messages": 0, \n'
                                    '    "vcards": 0\n'
                                    '}\n'))
     finally:
         self.mp._ui = old_ui
Ejemplo n.º 15
0
 def test_ui_clear_log(self):
     old_ui = self._ui_swap()
     try:
         self.mp._ui.block()
         with capture() as out:
             self.mp._ui.log(UserInteraction.LOG_URGENT, "urgent")
             self.mp._ui.log(UserInteraction.LOG_RESULT, "result")
             self.mp._ui.log(UserInteraction.LOG_ERROR, "error")
             self.mp._ui.log(UserInteraction.LOG_NOTIFY, "notify")
             self.mp._ui.log(UserInteraction.LOG_WARNING, "warning")
             self.mp._ui.log(UserInteraction.LOG_PROGRESS, "progress")
             self.mp._ui.log(UserInteraction.LOG_DEBUG, "debug")
             self.mp._ui.log(UserInteraction.LOG_ALL, "all")
             self.mp._ui.clear_log()
             self.mp._ui.unblock()
         self.assertEquals(out, ['', ''])
     finally:
         self.mp._ui = old_ui
Ejemplo n.º 16
0
 def test_ui_clear_log(self):
     old_ui = self._ui_swap()
     try:
         self.mp._ui.block()
         with capture() as out:
             self.mp._ui.log(UserInteraction.LOG_URGENT, "urgent")
             self.mp._ui.log(UserInteraction.LOG_RESULT, "result")
             self.mp._ui.log(UserInteraction.LOG_ERROR, "error")
             self.mp._ui.log(UserInteraction.LOG_NOTIFY, "notify")
             self.mp._ui.log(UserInteraction.LOG_WARNING, "warning")
             self.mp._ui.log(UserInteraction.LOG_PROGRESS, "progress")
             self.mp._ui.log(UserInteraction.LOG_DEBUG, "debug")
             self.mp._ui.log(UserInteraction.LOG_ALL, "all")
             self.mp._ui.clear_log()
             self.mp._ui.unblock()
         self.assertEquals(out, ['', ''])
     finally:
         self.mp._ui = old_ui
Ejemplo n.º 17
0
def test_no_fetch():
    """ Run 'git up' with '--no-fetch' argument """
    os.chdir(repo_path)

    from PyGitUp.gitup import GitUp
    gitup = GitUp(testing=True)
    gitup.should_fetch = False

    with capture() as [stdout, _]:
        gitup.run()

    stdout = stdout.getvalue()

    assert_false('Fetching' in stdout)

    assert_true('rebasing' in stdout)
    assert_true('up to date' in stdout)
    assert_true(test_name in stdout)
    assert_true(new_branch_name in stdout)
Ejemplo n.º 18
0
def test_version():
    """ Run 'git up': Check version """
    try:
        import pkg_resources as pkg
    except ImportError:
        raise SkipTest('pip not installed')

    try:
        socket.gethostbyname('pypi.python.org')
    except socket.error:
        raise SkipTest('Can\'t connect to PYPI')

    from PyGitUp.gitup import GitUp
    with capture() as [stdout, _]:
        GitUp(sparse=True).version_info()
    stdout = stdout.getvalue()

    package = pkg.get_distribution('git-up')
    local_version_str = package.version

    assert_in(local_version_str, stdout)
Ejemplo n.º 19
0
 def setUpClass(cls):
     sys.argv = ['architect', 'partition', '--module', 'tests.models.peewee']
     with capture() as (out, _):
         search = 'successfully (re)configured the database for the following models'
         assert search in out, '{0} not in {1}'.format(search, out)
Ejemplo n.º 20
0
 def setUpClass(cls):
     sys.argv = ['architect', 'partition', '--module', 'tests.models.sqlalchemy', '--connection', dsn]
     with capture() as (out, _):
         search = 'successfully (re)configured the database for the following models'
         assert search in out, '{0} not in {1}'.format(search, out)
     cls.session = sessionmaker(bind=engine)()
Ejemplo n.º 21
0
 def test_dsn_not_provided_error(self):
     from architect.exceptions import DsnNotProvidedError
     sys.argv = ['architect', 'partition', '--module', 'tests.models.sqlalchemy']
     with capture() as (_, err):
         self.assertIn(str(DsnNotProvidedError()).lower(), err.lower())
Ejemplo n.º 22
0
 def test_module_import_error(self):
     sys.argv.extend(['-m', 'foobar'])
     with capture() as (_, err):
         self.assertIn(str(ImportProblemError('no module named')), err)
Ejemplo n.º 23
0
 def test_command_invalid_argument(self):
     sys.argv.extend(['partition', '-m', 'foobar', '-foo', 'bar'])
     with capture() as (_, err):
         self.assertIn(
             str(CommandArgumentError(current='-foo bar',
                                      allowed='')).lower(), err)
Ejemplo n.º 24
0
 def test_no_command_provided_error(self):
     with capture() as (_, err):
         self.assertIn(
             str(CommandNotProvidedError(allowed=commands.keys())).lower(),
             err)
Ejemplo n.º 25
0
 def test_no_models_in_module_error(self):
     sys.argv.extend(['-m', 'contextlib'])
     with capture() as (out, _):
         self.assertIn('unable to find any partitionable models in a module', out)
Ejemplo n.º 26
0
 def test_no_command_provided_error(self):
     with capture() as (_, err):
         self.assertIn(str(CommandNotProvidedError(allowed=commands.keys())).lower(), err)
Ejemplo n.º 27
0
 def test_bad_dsn_provided_error(self):
     from architect.exceptions import DsnParseError
     sys.argv = ['architect', 'partition', '--module', 'tests.models.sqlalchemy', '--connection', 'foobar']
     with capture() as (_, err):
         self.assertIn(str(DsnParseError(current='foobar')).lower(), err.lower())
Ejemplo n.º 28
0
 def setUpClass(cls):
     sys.argv = ["architect", "partition", "--module", "tests.models.django"]
     with capture() as (out, _):
         search = "successfully (re)configured the database for the following models"
         assert search in out, "{0} not in {1}".format(search, out)
Ejemplo n.º 29
0
 def test_invalid_command_error(self):
     sys.argv.append('foobar')
     with capture() as (_, err):
         self.assertIn(str(CommandError(current='foobar', allowed=commands.keys())).lower(), err)
Ejemplo n.º 30
0
 def test_invalid_command_error(self):
     sys.argv.append('foobar')
     with capture() as (_, err):
         self.assertIn(
             str(CommandError(current='foobar',
                              allowed=commands.keys())).lower(), err)
Ejemplo n.º 31
0
 def test_command_invalid_argument(self):
     sys.argv.extend(['partition', '-m', 'foobar', '-foo', 'bar'])
     with capture() as (_, err):
         self.assertIn(str(CommandArgumentError(current='-foo bar', allowed='')).lower(), err)
Ejemplo n.º 32
0
 def test_required_arguments_error(self):
     with capture() as (_, err):
         self.assertIn('-m/--module', err)
Ejemplo n.º 33
0
 def test_required_arguments_error(self):
     with capture() as (_, err):
         self.assertIn('-m/--module', err)
Ejemplo n.º 34
0
 def test_no_models_in_module_error(self):
     sys.argv.extend(['-m', 'contextlib'])
     with capture() as (out, _):
         self.assertIn(
             'unable to find any partitionable models in a module', out)
Ejemplo n.º 35
0
 def test_module_import_error(self):
     sys.argv.extend(['-m', 'foobar'])
     with capture() as (_, err):
         self.assertIn(str(ImportProblemError('no module named')), err)