Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@
language_version: python3.5
- id: fix-encoding-pragma
language_version: python3.5
args: ['--remove']
- repo: https://github.com/asottile/reorder_python_imports
sha: v0.3.1
hooks:
- id: reorder-python-imports
language_version: python3.5
args: [
'--add-import', 'from __future__ import absolute_import',
'--add-import', 'from __future__ import unicode_literals',
'--remove-import', 'from __future__ import absolute_import',
'--remove-import', 'from __future__ import unicode_literals',
]
4 changes: 0 additions & 4 deletions lazy_build/cache.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import unicode_literals

import collections
import os
import tempfile
Expand Down
6 changes: 1 addition & 5 deletions lazy_build/cli.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import unicode_literals

import argparse
import json
import os
Expand Down Expand Up @@ -116,7 +112,7 @@ def main(argv=None):
# TODO: is there a way we can get argparse to do this for us?
if args.command[0] != '--':
raise ValueError(
'You must separate the command from the other arguments with a --!',
'You must separate the command from the other arguments with a --!', # noqa
)

del args.command[0]
Expand Down
4 changes: 0 additions & 4 deletions lazy_build/color.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
# -*- coding: utf-8 -*-
"""Stolen from ocflib.misc.shell"""
from __future__ import absolute_import
from __future__ import unicode_literals

import sys

# terminal text color wrappers;
Expand Down
4 changes: 0 additions & 4 deletions lazy_build/config.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import unicode_literals

import collections

from lazy_build import cache
Expand Down
7 changes: 1 addition & 6 deletions lazy_build/context.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import unicode_literals

import collections
import fnmatch
import hashlib
Expand Down Expand Up @@ -90,8 +86,7 @@ def build_context(conf, command):
if os.path.isdir(path) and not os.path.islink(path):
for child in os.listdir(path):
child = os.path.relpath(os.path.join(path, child))
if child not in explored:
fringe.add(child)
fringe.add(child)
else:
ctx[path] = FileContext.from_path(path)

Expand Down
6 changes: 0 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import unicode_literals

from setuptools import find_packages
from setuptools import setup

Expand All @@ -10,8 +6,6 @@
name='lazy-build',
version='0.0.0.dev1',
classifiers=[
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.5',
],
Expand Down
41 changes: 41 additions & 0 deletions tests/color_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import sys
from unittest import mock

import pytest

import lazy_build.color


COLORS = (
'black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white',
)


@pytest.mark.parametrize('color', COLORS)
def test_color_wrappers_with_tty(color):
with mock.patch.object(sys.stdout, 'isatty', return_value=True):
fore = getattr(lazy_build.color, color)
assert fore('hi') == fore('hi', tty_only=True)
assert fore('hi') == (
lazy_build.color.FG_CODES[color] +
'hi' +
lazy_build.color.FG_CODES['reset']
)

bg = getattr(lazy_build.color, 'bg_' + color)
assert bg('hi') == bg('hi', tty_only=True)
assert bg('hi') == (
lazy_build.color.BG_CODES[color] +
'hi' +
lazy_build.color.BG_CODES['reset']
)


@pytest.mark.parametrize('color', COLORS)
def test_color_wrappers_without_tty(color):
with mock.patch('sys.stdout.isatty', return_value=False):
fore = getattr(lazy_build.color, color)
assert fore('hi') == 'hi'

bg = getattr(lazy_build.color, 'bg_' + color)
assert bg('hi') == 'hi'
15 changes: 15 additions & 0 deletions tests/config_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from unittest import mock

from lazy_build import config


def test_from_args():
conf = config.Config.from_args(mock.Mock(
context=['requirements.txt', 'setup.py'],
ignore=['*.py[co]', '*.swp'],
output=['venv', 'node_modules'],
))
assert conf.context == {'requirements.txt', 'setup.py'}
assert conf.ignore == {'*.py[co]', '*.swp'}
assert conf.output == {'venv', 'node_modules'}
# TODO: make some assertions about the backend
68 changes: 63 additions & 5 deletions tests/context_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import unicode_literals
import io
import json
import os
import tarfile

import pytest

Expand Down Expand Up @@ -35,7 +36,7 @@ def test_build_context_simple(tmpdir):
conf = config.Config(
context={tmpdir.strpath, tmpdir.join('a').strpath},
ignore={'d'},
output=('output',),
output=None,
backend=None,
)
tmpdir.join('a').write(b'foo')
Expand All @@ -44,11 +45,68 @@ def test_build_context_simple(tmpdir):
tmpdir.join('d').mkdir()
tmpdir.join('d/e').write(b'baz')
tmpdir.join('f').mksymlinkto('/etc/passwd')
assert context.build_context(conf, 'command') == context.BuildContext(

ctx = context.build_context(conf, 'command')
assert ctx == context.BuildContext(
files={
'a': context.FileContext('file', context.hash(b'foo')),
'b/c': context.FileContext('file', context.hash(b'bar')),
'f': context.FileContext('link', context.hash(b'/etc/passwd')),
},
command='command',
)
assert ctx.hash == context.hash(
json.dumps(('command', ctx.files), sort_keys=True).encode('utf8'),
)


def test_package_artifact(tmpdir):
tmpdir.chdir()
tmpdir.join('a').ensure()
tmpdir.join('b').mkdir()
tmpdir.join('b/c').ensure()
tmpdir.join('c').ensure()

tmp = context.package_artifact(config.Config(
context=None,
ignore=None,
output=('b', 'c'),
backend=None,
))
try:
with tarfile.TarFile(tmp) as tf:
members = {member.name for member in tf.getmembers()}
finally:
os.remove(tmp)

assert members == {'b/c', 'c'}


def test_extract_artifact(tmpdir):
tmpdir.chdir()
tmpdir.join('my.txt').write('this is not the text you are looking for')
tmpdir.join('a').mkdir()
tmpdir.join('a/b').mkdir()
tmpdir.join('a/sup').ensure()
tmpdir.join('a/b/sup').ensure()

tar = tmpdir.join('my.tar').strpath
with tarfile.TarFile(tar, 'w') as tf:
for path in ('my.txt', 'hello/there.txt', 'a/b/c/d.txt'):
ti = tarfile.TarInfo(path)
ti.size = 6
tf.addfile(ti, fileobj=io.BytesIO(b'wuddup'))

context.extract_artifact(config.Config(
context=None,
ignore=None,
output=('my.txt', 'hello', 'a/b'),
backend=None,
), tar)

assert tmpdir.join('my.txt').read() == 'wuddup'
assert tmpdir.join('hello/there.txt').isfile()
assert tmpdir.join('a/b/c/d.txt').isfile()

assert tmpdir.join('a/sup').isfile()
assert not tmpdir.join('a/b/sup').isfile()
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = py27,py35
envlist = py35

[testenv]
deps = -rrequirements-dev.txt
Expand All @@ -22,7 +22,7 @@ deps =
commands =

[flake8]
max-line-length = 119
max-line-length = 79

[pep8]
ignore = E265,E309,E501