Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Pascal MOLIN
lektor-commit
Commits
f87f95be
Commit
f87f95be
authored
Mar 30, 2021
by
Pascal
Browse files
use new conftest
parent
728aecd5
Changes
3
Hide whitespace changes
Inline
Side-by-side
setup.cfg
View file @
f87f95be
...
...
@@ -6,9 +6,10 @@ addopts = -v
markers =
base
server
#
testpaths =
#
test
testpaths =
test
project = /Users/pascal/git/lektor-test-site/
branch = lektor-commit
packages =
/Users/pascal/git/lektor-admin-extra/
/Users/pascal/git/lektor-login/
test/conftest.py
View file @
f87f95be
...
...
@@ -15,13 +15,25 @@ sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')
from
git
import
Repo
def
pytest_addoption
(
parser
):
parser
.
addini
(
'project'
,
'path of a the lektor test project'
)
parser
.
addoption
(
"--project"
,
action
=
"store"
)
parser
.
addini
(
'project'
,
'path or git repo of the lektor test project'
)
parser
.
addoption
(
"--branch"
,
action
=
"append"
)
parser
.
addini
(
'branch'
,
'git branches to checkout'
,
'linelist'
,
default
=
[
'master'
])
parser
.
addoption
(
"--package"
,
action
=
"append"
)
parser
.
addini
(
'packages'
,
'plugins path to add'
,
'linelist'
)
# dunno how pathlist is parsed
parser
.
addoption
(
"--port"
,
action
=
"store"
)
parser
.
addini
(
'port'
,
'http server port'
,
default
=
'5787'
)
def
get_config
(
config
,
name
):
v
=
config
.
getoption
(
name
)
if
v
is
None
:
v
=
config
.
getini
(
name
)
print
(
name
,
v
)
return
v
@
pytest
.
fixture
(
scope
=
'session'
)
def
project_path
(
request
):
return
request
.
config
.
getini
(
'project'
)
return
get_config
(
request
.
config
,
'project'
)
@
pytest
.
fixture
(
scope
=
'session'
)
def
port
(
request
):
...
...
@@ -31,39 +43,39 @@ def port(request):
def
packages
(
request
):
return
request
.
config
.
getini
(
'packages'
)
def
git_clone
(
project_path
,
output_path
,
branchname
=
'master'
):
subprocess
.
run
(
[
"git"
,
"clone"
,
"--single-branch"
,
"--branch"
,
branchname
,
"--recurse-submodules"
,
project_path
],
check
=
True
,
cwd
=
output_path
)
def
pytest_generate_tests
(
metafunc
):
branches
=
get_config
(
metafunc
.
config
,
'branch'
)
if
'branchname'
in
metafunc
.
fixturenames
:
metafunc
.
parametrize
(
"branchname"
,
branches
,
scope
=
'session'
)
@
pytest
.
fixture
(
scope
=
'session'
)
def
lektorproject
(
project_path
,
packages
):
try
:
output_path
=
tempfile
.
mkdtemp
()
print
(
'OUT: '
,
output_path
)
# copy main repo
print
(
'PROJECT: '
,
project_path
)
# copy with git repo
print
(
'COPY project'
)
shutil
.
copytree
(
project_path
,
output_path
,
dirs_exist_ok
=
True
)
def
ignore
(
path
,
names
):
# no symlink
remove
=
set
(
name
for
name
in
names
if
name
in
[
'.git'
,
'test'
,
'content'
,
'__pycache__'
,
'.pytest_cache'
]
or
name
.
endswith
(
'.egg-info'
)
or
os
.
path
.
islink
(
os
.
path
.
join
(
path
,
name
))
)
print
(
'folder %s -> remove %s'
%
(
path
,
remove
))
return
remove
# add local modifications
print
(
'COPY local folders, except symlinks'
)
if
os
.
path
.
isdir
(
'test/site'
):
shutil
.
copytree
(
'test/site'
,
output_path
,
ignore
=
ignore
,
dirs_exist_ok
=
True
)
# add packages and current plugin
#testdir = shutil.ignore_patterns('test', '.git', '.egg*', '__pycache*')
for
p
in
packages
+
[
os
.
getcwd
()
]:
print
(
'COPY package %s'
%
p
)
p
=
os
.
path
.
normpath
(
p
)
name
=
os
.
path
.
basename
(
p
)
shutil
.
copytree
(
p
,
os
.
path
.
join
(
output_path
,
'packages'
,
name
),
ignore
=
ignore
,
dirs_exist_ok
=
True
)
except
(
OSError
,
IOError
)
as
e
:
pytest
.
exit
(
'FATAL: could not copy test site directory. %s'
,
e
)
# error
def
lektorproject
(
project_path
,
branchname
,
packages
):
output_path
=
tempfile
.
mkdtemp
()
print
(
'OUT: '
,
output_path
)
# copy main repo
print
(
'CLONE %s to %s'
%
(
project_path
,
output_path
))
git_clone
(
project_path
,
output_path
,
branchname
)
name
=
os
.
path
.
basename
(
os
.
path
.
normpath
(
project_path
))
output_path
=
os
.
path
.
join
(
output_path
,
name
)
packages_path
=
os
.
path
.
join
(
output_path
,
'packages'
)
os
.
mkdir
(
packages_path
)
for
p
in
packages
+
[
os
.
getcwd
()
]:
print
(
'CLONE package %s to %s'
%
(
p
,
packages_path
))
p
=
os
.
path
.
normpath
(
p
)
git_clone
(
p
,
packages_path
)
print
(
'OUTPUT PATH = %s'
%
output_path
)
yield
output_path
...
...
@@ -77,6 +89,19 @@ def git(lektorproject):
repo
=
Repo
(
lektorproject
)
yield
repo
@
pytest
.
fixture
(
scope
=
'function'
)
def
gitmodif
(
lektorproject
):
tree
=
[
'top.txt'
,
'tmp/toto.txt'
,
'tmp/temp.txt'
]
for
name
in
tree
:
f
=
os
.
path
.
join
(
lektorproject
,
name
)
os
.
makedirs
(
os
.
path
.
dirname
(
f
),
exist_ok
=
True
)
subprocess
.
run
([
'touch'
,
name
],
cwd
=
lektorproject
)
yield
tree
for
name
in
tree
:
os
.
remove
(
os
.
path
.
join
(
lektorproject
,
name
))
class
BaseUrlSession
(
requests
.
Session
):
# https://github.com/requests/toolbelt/blob/master/requests_toolbelt/sessions.py
def
__init__
(
self
,
base_url
=
None
):
...
...
@@ -95,7 +120,6 @@ class BaseUrlSession(requests.Session):
"""Create the URL based off this partial path."""
return
urljoin
(
self
.
base_url
,
url
)
@
pytest
.
fixture
(
scope
=
'module'
)
def
server
(
lektorproject
,
port
):
...
...
@@ -132,9 +156,9 @@ def anonymous(server):
session
.
close
()
@
pytest
.
fixture
(
scope
=
'function'
)
def
test
(
server
):
def
view
(
server
):
session
=
BaseUrlSession
(
base_url
=
server
.
base_url
)
login
(
session
,
'
test
'
)
login
(
session
,
'
view
'
)
yield
session
session
.
close
()
...
...
@@ -144,3 +168,17 @@ def admin(server):
login
(
session
,
'admin'
)
yield
session
session
.
close
()
@
pytest
.
fixture
(
scope
=
'function'
)
def
blog
(
server
):
session
=
BaseUrlSession
(
base_url
=
server
.
base_url
)
login
(
session
,
'blog'
)
yield
session
session
.
close
()
@
pytest
.
fixture
(
scope
=
'function'
)
def
draft
(
server
):
session
=
BaseUrlSession
(
base_url
=
server
.
base_url
)
login
(
session
,
'draft'
)
yield
session
session
.
close
()
test/test_git.py
View file @
f87f95be
import
pytest
@
pytest
.
mark
.
base
def
test_status
(
git
):
def
test_status
(
git
,
gitmodif
):
rv
=
git
.
status
()
assert
'??
configs
'
in
str
(
rv
)
assert
'??
tmp
'
in
str
(
rv
)
@
pytest
.
mark
.
base
def
test_git_session
(
git
):
def
test_git_session
(
git
,
gitmodif
):
print
(
"[1] add
configs
folder"
)
rv
=
git
.
add
(
'
configs
'
)
assert
rv
,
"[1] add
folder
configs"
print
(
"[1] add
tmp
folder"
)
rv
=
git
.
add
(
'
tmp
'
)
assert
rv
,
"[1] add
two
configs"
rv
=
git
.
status
()
assert
'A
configs/login.ini
'
in
str
(
rv
),
"[1] after add"
assert
'A
tmp/toto.txt
'
in
str
(
rv
),
"[1] after add"
print
(
"[2] commit this addition"
)
rv
=
git
.
commit
(
'add
configs
'
,
'pytest <dev@null>'
)
rv
=
git
.
commit
(
'add
tmp
'
,
'pytest <dev@null>'
)
assert
rv
,
"[2] commit"
rv
=
git
.
status
()
assert
'
configs/login.ini
'
not
in
str
(
rv
),
"[2] after commit"
assert
'
tmp
'
not
in
str
(
rv
),
"[2] after commit"
print
(
"[3] commit untracked files"
)
rv
=
git
.
commit_tree
(
'add all files'
,
'pytest <dev@null>'
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment