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)
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'))
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)
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)
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))
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'))
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')
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'))
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')
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')
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))
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))
def test_repr(self): self.assertEqual(repr(Profile('user/repo')), "Profile('user/repo')")
def test_retrieve_cannotDownloadProfile_raisesError(self): profile = Profile('non_existant/vimrc') self.assertRaises(IOError, self.profileRetriever.retrieve, profile)
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'))
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')
def test_getDirName_withoutSlashes_isUnchanged(self): profile = Profile('repo') self.assertEquals(profile.getDirName(), 'repo') profile = Profile('prefix.repo') self.assertEquals(profile.getDirName(), 'prefix.repo')
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')
def test_retrieve_prints(self, stdout): profile = Profile('test/vimrc') self.profileRetriever.retrieve(profile) self.assertStdout(stdout, 'Downloading profile from .*')
def test_execute_printsCurrentProfile(self, stdout): self.app.settings.currentProfile = Profile('test/vimrc') self.action.execute() self.assertStdout(stdout, 'Current profile: test/vimrc')
def test_getDirName_withoutSlashes_isUnchanged(self): profile = Profile('repo') self.assertEquals(profile.getDirName(), 'repo') profile = Profile('prefix.repo') self.assertEquals(profile.getDirName(), 'prefix.repo')
def test_equal(self): profile1 = Profile('user/repo') profile2 = Profile('user/repo') self.assertEqual(profile1, profile2)
def test_notEqual(self): self.assertNotEqual(Profile('user/repo1'), Profile('user/repo2')) self.assertNotEqual(Profile('user/repo1'), None) self.assertNotEqual(None, Profile('user/repo2'))
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')