예제 #1
0
    def test_it_should_update_skills_correctly(self):
        s = SkillsManager('skills')
        p = os.path.abspath('skills')

        with patch('os.path.isdir', return_value=True):
            with patch('os.path.isfile', return_value=False):
                with patch('subprocess.check_output') as sub_mock:
                    succeeded, failed = s.update('a/skill', 'another__one',
                                                 'https://github.com/a/third')

                    expect(succeeded).to.equal(
                        ['a/skill', 'another/one', 'a/third'])
                    expect(failed).to.be.empty

                    expect(sub_mock.call_count).to.equal(3)
                    sub_mock.assert_has_calls([
                        call(['git', 'pull'],
                             cwd=os.path.join(p, 'a__skill'),
                             stderr=subprocess.STDOUT),
                        call(['git', 'pull'],
                             cwd=os.path.join(p, 'another__one'),
                             stderr=subprocess.STDOUT),
                        call(['git', 'pull'],
                             cwd=os.path.join(p, 'a__third'),
                             stderr=subprocess.STDOUT),
                    ])
예제 #2
0
    def test_it_should_complain_when_updating_unknown_skills(self):
        s = SkillsManager('skills')

        with patch('os.path.isdir', return_value=False):
            succeeded, failed = s.update('a/skill', 'another__one',
                                         'https://github.com/a/third')

            expect(failed).to.equal(['a/skill', 'another/one', 'a/third'])
            expect(succeeded).to.be.empty
예제 #3
0
    def test_it_should_update_all_skills_if_no_one_provided(self):
        s = SkillsManager('skills')

        with patch('os.listdir', return_value=['one', 'two']):
            with patch('os.path.isdir', return_value=True):
                with patch('subprocess.check_output') as sub_mock:
                    succeeded, failed = s.update()

                    expect(succeeded).to.equal(['one', 'two'])
                    expect(failed).to.be.empty
예제 #4
0
    def test_it_should_complain_when_update_failed(self):
        s = SkillsManager('skills')

        with patch('os.path.isdir', return_value=True):
            with patch('subprocess.check_output',
                       side_effect=subprocess.CalledProcessError(
                           42, 'cmd')) as sub_mock:
                succeeded, failed = s.update('a/skill', 'another__one',
                                             'https://github.com/a/third')

                expect(failed).to.equal(['a/skill', 'another/one', 'a/third'])
                expect(succeeded).to.be.empty
예제 #5
0
    def test_it_should_install_dependencies_when_updating(self):
        s = SkillsManager('skills')
        p = os.path.abspath('skills')

        with patch('os.path.isdir', return_value=True):
            with patch('os.path.isfile', return_value=True):
                with patch('builtins.open', mock_open(read_data='')):
                    with patch('subprocess.check_output') as sub_mock:
                        succeeded, failed = s.update('my/skill')

                        expect(succeeded).to.equal(['my/skill'])
                        expect(failed).to.be.empty

                        expect(sub_mock.call_count).to.equal(2)
                        sub_mock.assert_has_calls([
                            call(['git', 'pull'],
                                 cwd=os.path.join(p, 'my__skill'),
                                 stderr=subprocess.STDOUT),
                            call(['pip', 'install', '-r', 'requirements.txt'],
                                 cwd=os.path.join(p, 'my__skill'),
                                 stderr=subprocess.STDOUT),
                        ])