Esempio n. 1
0
    def test_execute_withProfile_updatesProfile(self):
        self.updateProfileAction.profile = Profile('test/vimrc')

        self.updateProfileAction.execute()

        self.assertTrue(self.switchProfileAction.execute.called)
        self.assertEqual(self.switchProfileAction.profile,
                         Profile('test/vimrc'))
        self.assertEqual(self.switchProfileAction.update, True)
Esempio n. 2
0
    def test_saveSettings_allAttributes(self):
        settings = Settings()
        settings.currentProfile = Profile('test/vimrc')
        configFilePath = self.getTestPath('vimswitchrc')

        self.configFile.saveSettings(settings, configFilePath)

        newSettings = Settings()
        self.configFile.loadSettings(newSettings, configFilePath)
        self.assertEqual(newSettings.currentProfile, Profile('test/vimrc'))
Esempio n. 3
0
    def test_execute_withoutProfile_updatesCurrentProfile(self):
        self.settings.currentProfile = Profile('test/currentProfile')
        self.updateProfileAction.profile = None

        self.updateProfileAction.execute()

        self.assertTrue(self.switchProfileAction.execute.called)
        self.assertEqual(self.switchProfileAction.profile,
                         Profile('test/currentProfile'))
        self.assertEqual(self.switchProfileAction.update, True)
Esempio n. 4
0
    def test_getProfileUrl_convertsUserSlashRepo(self):
        profile = Profile('testuser/testrepo')

        url = getProfileUrl(profile)

        expectedUrl = 'https://github.com/testuser/testrepo/archive/master.zip'
        self.assertEqual(url, expectedUrl)
Esempio n. 5
0
    def test_createEmptyProfile_profileDoesNotExist_createsProfileDir(self):
        profile = Profile('default')

        self.profileCache.createEmptyProfile(profile)

        profileDir = self.getTestPath('.vimswitch/profiles/default')
        self.assertTrue(self.diskIo.dirExists(profileDir))
Esempio n. 6
0
    def test_parse_updateProfileAction(self):
        argv = './vimswitch --update test/vimrc'.split()

        self.commandLineParser.parse(argv)

        self.assertEqual(self.commandLineParser.action, 'updateProfile')
        self.assertEqual(self.commandLineParser.profile, Profile('test/vimrc'))
Esempio n. 7
0
 def setUp(self):
     FileSystemTestCase.setUp(self)
     self.diskIo = DiskIo()
     self.settings = Settings(self.getWorkingDir())
     self.diskIo.createDirWithParents(self.settings.cachePath)
     self.profileCache = ProfileCache(self.settings, self.diskIo)
     self.testProfile = Profile('test/vimrc')
Esempio n. 8
0
    def test_loadSettings_allAttributes(self):
        self.copyDataToWorkingDir('vimswitchrc', 'vimswitchrc')
        configFilePath = self.getTestPath('vimswitchrc')
        settings = Settings()

        self.configFile.loadSettings(settings, configFilePath)

        self.assertEqual(settings.currentProfile, Profile('test/vimrc'))
Esempio n. 9
0
    def test_execute_withDefaultProfile_printError(self, stdout):
        self.updateProfileAction.profile = Profile('default')

        self.updateProfileAction.execute()

        self.assertFalse(self.switchProfileAction.execute.called)
        self.assertEqual(self.updateProfileAction.exitCode, -1)
        self.assertStdout(stdout, 'Cannot update default profile')
Esempio n. 10
0
 def setUp(self):
     self.profile = Profile('test/vimrc')
     self.settings = Settings(os.path.normpath('/home/foo'))
     self.diskIo = Stubs.DiskIoStub()
     # We use the real ProfileCache (with stubbed dependencies) because
     # ProfileCache.getProfileLocation gets called by ProfileCopier
     self.profileCache = ProfileCache(self.settings, self.diskIo)
     self.profileDataIo = Stubs.ProfileDataIoStub()
     self.profileCopier = ProfileCopier(self.settings, self.profileCache,
                                        self.profileDataIo)
 def setUp(self):
     FileSystemTestCase.setUp(self)
     self.app = Application()
     self.app.settings = Settings(self.getWorkingDir())
     self.app.fileDownloader = createFakeFileDownloader(
         self.app, self.getDataPath('fake_internet'))
     self.switchProfileAction = createSwitchProfileAction(self.app)
     self.app.diskIo.createDirWithParents(self.app.settings.cachePath)
     self.app.diskIo.createDirWithParents(self.app.settings.downloadsPath)
     self.profile = Profile('test/vimrc')
Esempio n. 12
0
    def test_retrieve_retrievesProfile(self):
        profile = Profile('test/vimrc')

        self.profileRetriever.retrieve(profile)

        vimDirPath = self.getTestPath('.vimswitch/profiles/test.vimrc/.vim')
        vimrcFilePath = self.getTestPath('.vimswitch/profiles/test.vimrc/.vimrc')
        actualVimrcContent = self.diskIo.getFileContents(vimrcFilePath)
        expectedVimrcContent = '" test vimrc data'
        self.assertEqual(actualVimrcContent, expectedVimrcContent)
        self.assertTrue(self.diskIo.dirExists(vimDirPath))
Esempio n. 13
0
    def test_retrieve_profileAlreadyCached_overwritesProfile(self):
        profile = Profile('test/vimrc')
        profileDirPath = self.getTestPath('.vimswitch/profiles/test.vimrc')
        vimDirPath = self.getTestPath('.vimswitch/profiles/test.vimrc/.vim')
        vimrcFilePath = self.getTestPath('.vimswitch/profiles/test.vimrc/.vimrc')
        self.diskIo.createDir(profileDirPath)
        self.diskIo.createDir(vimDirPath)
        self.diskIo.createFile(vimrcFilePath, '" previous data')

        self.profileRetriever.retrieve(profile)

        actualVimrcContent = self.diskIo.getFileContents(vimrcFilePath)
        expectedVimrcContent = '" test vimrc data'
        self.assertEqual(actualVimrcContent, expectedVimrcContent)
        self.assertTrue(self.diskIo.dirExists(vimDirPath))
Esempio n. 14
0
 def test_repr(self):
     self.assertEqual(repr(Profile('user/repo')), "Profile('user/repo')")
Esempio n. 15
0
    def test_retrieve_cannotDownloadProfile_raisesError(self):
        profile = Profile('non_existant/vimrc')

        self.assertRaises(IOError, self.profileRetriever.retrieve, profile)
Esempio n. 16
0
 def test_getProfileLocation(self):
     self.settings.cachePath = '/foo/bar/cachePath'
     profile = Profile('test/vimrc')
     result = self.profileCache.getProfileLocation(profile)
     self.assertEquals(result,
                       os.path.normpath('/foo/bar/cachePath/test.vimrc'))
Esempio n. 17
0
 def test_getDirName_withSlashes_replacedByDot(self):
     profile = Profile('user/repo')
     self.assertEquals(profile.getDirName(), 'user.repo')
     profile = Profile('user/prefix.repo')
     self.assertEquals(profile.getDirName(), 'user.prefix.repo')
Esempio n. 18
0
 def test_getDirName_withoutSlashes_isUnchanged(self):
     profile = Profile('repo')
     self.assertEquals(profile.getDirName(), 'repo')
     profile = Profile('prefix.repo')
     self.assertEquals(profile.getDirName(), 'prefix.repo')
Esempio n. 19
0
 def setUp(self):
     app = Application()
     app.diskIo = DiskIoStub()  # Fake all disk operations
     self.commandLineParser = CommandLineParser()
     self.actionResolver = ActionResolver(app, self.commandLineParser)
     self.profile = Profile('test/vimrc')
Esempio n. 20
0
    def test_retrieve_prints(self, stdout):
        profile = Profile('test/vimrc')

        self.profileRetriever.retrieve(profile)

        self.assertStdout(stdout, 'Downloading profile from .*')
Esempio n. 21
0
    def test_execute_printsCurrentProfile(self, stdout):
        self.app.settings.currentProfile = Profile('test/vimrc')

        self.action.execute()

        self.assertStdout(stdout, 'Current profile: test/vimrc')
Esempio n. 22
0
 def test_getDirName_withoutSlashes_isUnchanged(self):
     profile = Profile('repo')
     self.assertEquals(profile.getDirName(), 'repo')
     profile = Profile('prefix.repo')
     self.assertEquals(profile.getDirName(), 'prefix.repo')
Esempio n. 23
0
    def test_equal(self):
        profile1 = Profile('user/repo')
        profile2 = Profile('user/repo')

        self.assertEqual(profile1, profile2)
Esempio n. 24
0
 def test_notEqual(self):
     self.assertNotEqual(Profile('user/repo1'), Profile('user/repo2'))
     self.assertNotEqual(Profile('user/repo1'), None)
     self.assertNotEqual(None, Profile('user/repo2'))
Esempio n. 25
0
 def test_getDirName_withSlashes_replacedByDot(self):
     profile = Profile('user/repo')
     self.assertEquals(profile.getDirName(), 'user.repo')
     profile = Profile('user/prefix.repo')
     self.assertEquals(profile.getDirName(), 'user.prefix.repo')