Пример #1
0
    def test_it_should_install_skills_and_their_dependencies(self):
        s = SkillsManager('skills')
        p = os.path.abspath('skills')

        with patch('subprocess.check_output') as sub_mock:
            with patch('os.path.isfile', return_value=True):
                with patch('builtins.open', mock_open(read_data='')):
                    succeeded, failed = s.install(
                        'a/skill', 'https://gitlab.com/a/third')

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

                    expect(sub_mock.call_count).to.equal(4)
                    sub_mock.assert_has_calls([
                        call([
                            'git', 'clone', 'https://github.com/a/skill',
                            os.path.join(p, 'a__skill')
                        ],
                             stderr=subprocess.STDOUT),
                        call(['pip', 'install', '-r', 'requirements.txt'],
                             cwd=os.path.join(p, 'a__skill'),
                             stderr=subprocess.STDOUT),
                        call([
                            'git', 'clone', 'https://gitlab.com/a/third',
                            os.path.join(p, 'a__third')
                        ],
                             stderr=subprocess.STDOUT),
                        call(['pip', 'install', '-r', 'requirements.txt'],
                             cwd=os.path.join(p, 'a__third'),
                             stderr=subprocess.STDOUT),
                    ])
Пример #2
0
    def test_it_should_update_skills_when_it_already_exists(self):
        s = SkillsManager('skills')
        p = os.path.abspath('skills')

        with patch('os.path.isdir', return_value=True):
            with patch('subprocess.check_output') as sub_mock:
                succeeded, failed = s.install('a/skill')

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

                expect(sub_mock.call_count).to.equal(1)
                sub_mock.assert_called_once_with(['git', 'pull'],
                                                 cwd=os.path.join(
                                                     p, 'a__skill'),
                                                 stderr=subprocess.STDOUT)
Пример #3
0
    def test_it_should_complain_when_install_failed_and_cleanup_skill_folder(
            self):
        s = SkillsManager('skills')

        with patch('subprocess.check_output',
                   side_effect=subprocess.CalledProcessError(
                       42, 'cmd')) as sub_mock:
            with patch('os.path.isfile', return_value=True):
                with patch('pytlas.supporting.manager.rmtree') as rm_mock:
                    succeeded, failed = s.install('my/skill')

                    expect(failed).to.equal(['my/skill'])
                    expect(succeeded).to.be.empty
                    rm_mock.assert_called_once_with(
                        os.path.abspath('skills/my__skill'),
                        ignore_errors=True)
Пример #4
0
    def test_it_should_allow_installation_of_compatible_skills(self):
        s = SkillsManager('skills')
        p = os.path.abspath('skills')

        compatible_version_spec = f'{__title__}[snips]~={__version__[0]}.0'

        with patch('subprocess.check_output') as sub_mock:
            with patch('os.path.isfile', return_value=True):
                with patch(
                        'builtins.open',
                        mock_open(
                            read_data=
                            f'{compatible_version_spec}\n\nrequests~=2.22')):
                    succeeded, failed = s.install('incompatible/skill')

                    expect(failed).to.be.empty
                    expect(succeeded).to.equal(['incompatible/skill'])
Пример #5
0
    def test_it_should_not_allow_installation_of_incompatible_skills(self):
        s = SkillsManager('skills')
        p = os.path.abspath('skills')

        incompatible_version_spec = f'{__title__}[snips]~={int(__version__[0]) - 1}.0'

        with patch('subprocess.check_output') as sub_mock:
            with patch('os.path.isfile', return_value=True):
                with patch(
                        'builtins.open',
                        mock_open(
                            read_data=
                            f'{incompatible_version_spec}\n\nrequests~=2.22')):
                    with patch('pytlas.supporting.manager.rmtree') as rm_mock:
                        succeeded, failed = s.install('incompatible/skill')

                        expect(succeeded).to.be.empty
                        expect(failed).to.equal(['incompatible/skill'])
                        rm_mock.assert_called_once_with(os.path.join(
                            p, 'incompatible__skill'),
                                                        ignore_errors=True)