Move package manager to blender branch

Moved the package manger out of an addon. It now lives here:
https://developer.blender.org/diffusion/B/browse/soc-2017-package_manager/

This repository still contains the repo generation script, the readme
has been updated to reflect this.
This commit is contained in:
Ellwood Zwovic
2017-08-29 04:30:49 -07:00
parent b27db0ca1f
commit ee0bbca8e5
15 changed files with 30 additions and 3008 deletions

View File

@@ -5,7 +5,12 @@ from pathlib import Path
import logging
import ast
import json
import bpkg-repogen
import types
import importlib.machinery
loader = importlib.machinery.SourceFileLoader('generate_repository', 'generate_repository')
generate_repository = types.ModuleType(loader.name)
loader.exec_module(generate_repository)
logging.basicConfig(level=logging.ERROR,
format='%(levelname)8s: %(message)s')
@@ -18,19 +23,11 @@ class TestRepoGeneration(unittest.TestCase):
def test_extract_blinfo_from_nonexistent(self):
test_file = 'file_that_doesnt_exist'
with self.assertRaises(FileNotFoundError):
bpkg-repogen.extract_blinfo(self.addon_path / test_file)
generate_repository.extract_blinfo(self.addon_path / test_file)
def test_package_quantity(self):
repo = bpkg-repogen.bpkg-repogen(self.addon_path, "name of the repo")
acceptible_addons = [
f for f in self.addon_path.iterdir()
if not f.match('*nonaddon*')
]
self.assertEqual(len(repo.packages), len(acceptible_addons))
def test_bpkg-repogen_from_nonexistent(self):
def test_generate_repository_from_nonexistent(self):
with self.assertRaises(FileNotFoundError):
bpkg-repogen.bpkg-repogen(Path('in_a_galaxy_far_far_away'), "somename")
generate_repository.make_repo(Path('in_a_galaxy_far_far_away'), "somename", "someurl")
# addons which should contain bl_infos
yes_blinfo = [
@@ -45,7 +42,7 @@ no_blinfo = [
def generate_good_blinfo_test(test_file: Path):
def test(self):
reality = bpkg-repogen.extract_blinfo(test_file)
reality = generate_repository.extract_blinfo(test_file)
with (self.helper_path / 'expected_blinfo').open("r") as f:
expectation = ast.literal_eval(f.read())
self.assertEqual(expectation, reality)
@@ -53,8 +50,8 @@ def generate_good_blinfo_test(test_file: Path):
def generate_bad_blinfo_test(test_file: Path):
def test(self):
with self.assertRaises(bpkg-repogen.BadAddon):
bpkg-repogen.extract_blinfo(test_file)
with self.assertRaises(generate_repository.BadAddon):
generate_repository.extract_blinfo(test_file)
return test
# Add test method retur

View File

@@ -1,72 +0,0 @@
import requests
import unittest
from unittest import mock
# from blenderpack import Repositories, fetch_repo
from datetime import datetime
import json
# based on https://stackoverflow.com/a/28507806/2730823
# This method will be used by the mock to replace requests.get
def mocked_requests_get(*args, **kwargs):
cidict = requests.structures.CaseInsensitiveDict
req_headers = cidict(kwargs.get('headers'))
t_fmt = '%a, %m %b %Y %X %Z'
class MockResponse:
def __init__(self, headers: cidict, status_code: int):
self.headers = headers
self.status_code = status_code
def json(self):
return json.dumps({'url': 'http://someurl.tld/repo.json'})
if args[0] == 'http://someurl.tld/repo.json':
resp_headers = cidict({
"ETag": '"2a0094b-b74-55326ced274f3"',
"Last-Modified": 'Sun, 13 Mar 2011 13:38:53 GMT',
})
if req_headers == {}:
resp_code = 200
else:
req_headers = cidict(req_headers)
resp_code = 304 if req_headers.get('if-none-match', '') == resp_headers['etag']\
or datetime.strptime(req_headers.get('if-modified-since', ''), t_fmt) < \
datetime.strptime(resp_headers['last-modified'], t_fmt) \
else 200
return MockResponse(resp_headers, resp_code)
return MockResponse(None, 404)
class MockRepositories:
storage = {}
def load(self, *args, **kwargs):
if args[0] not in self.storage:
self.storage[args[0]] = {'url': args[0]}
return self.storage[args[0]]
def write(self, *args, **kwargs):
self.storage[args[0]['url']] = args[0]
class fetch_url_twice(unittest.TestCase):
@mock.patch('requests.get', side_effect=mocked_requests_get)
def test_fetch(self, mock_get):
self.fail('unfinished test')
repos = MockRepositories()
fetch_repo('http://someurl.tld/repo.json', repos)
mock_get.assert_called_with('http://someurl.tld/repo.json', headers={})
fetch_repo('http://someurl.tld/repo.json', repos)
mock_get.assert_called_with('http://someurl.tld/repo.json', headers={
'If-None-Match': '"2a0094b-b74-55326ced274f3"',
'If-Modified-Since': 'Sun, 13 Mar 2011 13:38:53 GMT'
})
if __name__ == '__main__':
unittest.main()

View File

@@ -1,65 +0,0 @@
#!/usr/bin/env python3
import unittest
from pathlib import Path
import logging
import json
import bpackage as BP
logging.basicConfig(level=logging.DEBUG,
format='%(levelname)8s: %(message)s')
class TestRepoInstantiation(unittest.TestCase):
"""
Tests of the creation of a Repository object
"""
# helper_path = Path('tests/test_helpers')
# repos = blenderpack.Repositories(helper_path / 'repo.json')
# def test_load(self):
# repo = self.repos.load('http://someurl.tld/repo.json')
repo_dict = {
'name': 'The Best Repo Ever',
'url': 'http://someurl.tld/repo.json',
'packages': [
{'name': 'pkg1'},
{'name': 'pkg2'},
],
}
def test_create_from_dict(self):
"""
Instantiate repository repository with a dict and check
if all the items are carried over
"""
repodict = self.repo_dict
repo = BP.Repository(repodict)
for key, val in repodict.items():
self.assertEqual(getattr(repo, key), val)
def test_create_from_none(self):
"""
Instantiate repository repository from none and check that
the new repository's properties are set to none
"""
repodict = self.repo_dict
repo = BP.Repository(None)
for key, val in repodict.items():
self.assertEqual(getattr(repo, key), None)
def test_create_from_incomplete(self):
"""
Instantiate repository repository from a partial dict
and check that all properties are set, either to None or to the
value from the dict
"""
repodict = {
'name': 'The Best Repo Ever',
}
repo = BP.Repository(repodict)
for key, val in repodict.items():
self.assertEqual(getattr(repo, key), val)
self.assertIs(repo.url, None)