def test_copy_to_version(ctx): files = """ - package.json: | { "version": "1.1.2" } - foo.txt: hello world """ with create_files(files) as directory: version.copy_to_version( ctx.init(pkg=Package()), 'foo.txt', kind='pkg' ) assert 'foo-1.1.2.txt' in os.listdir('.') with open('foo.txt', 'w') as fp: fp.write('goodbye world') # shouldn't change versioned resources.. version.copy_to_version( ctx.init(pkg=Package()), 'foo.txt', kind='pkg' ) print open('foo-1.1.2.txt').read() assert open('foo-1.1.2.txt').read() == 'hello world' # .. update versioned resources when forcing version.copy_to_version( ctx.init(pkg=Package()), 'foo.txt', kind='pkg', force=True ) print open('foo-1.1.2.txt').read() assert open('foo-1.1.2.txt').read() == 'goodbye world'
def test_nested_directory2(): fdef = """ foo: bar: baz: hello: world """ with create_files(fdef, cleanup=True) as workdir: print "WORKDIR:", workdir print tree(workdir) foodir = os.path.join(workdir, 'foo') assert os.path.isdir(foodir) bardir = os.path.join(workdir, 'foo', 'bar') assert os.path.isdir(bardir) assert set(os.listdir(foodir)) == {'bar'} bazdir = os.path.join(workdir, 'foo', 'bar', 'baz') assert os.path.isdir(bazdir) assert os.listdir(bazdir) == ['hello'] hello = os.path.join(bazdir, 'hello') assert os.path.isfile(hello) assert open(hello).read() == "world"
def test_getmtime(): files = """ b: hello """ with create_files(files) as _root: root = path.Path(_root) assert os.path.getmtime(root/'b') == (root/'b').getmtime()
def test_access(): files = """ b: hello """ with create_files(files) as _root: b = path.Path(_root) / 'b' assert b.access(os.R_OK)
def test_rename(): files = """ a """ with create_files(files) as _root: root = path.Path(_root) assert os.listdir(root) == ['a'] (root / 'a').rename('b') assert os.listdir(root) == ['b']
def test_create_file_content2(): fdef = """ foo.txt: hello world """ with create_files(fdef, cleanup=True) as workdir: print "WORKDIR:", workdir print tree(workdir) assert tree(workdir) == [os.path.join(workdir, 'foo.txt')] assert open(os.path.join(workdir, 'foo.txt')).read() == 'hello world'
def test_utime(): files = """ a """ with create_files(files) as _root: root = path.Path(_root) t = time.time() stat = root.utime() assert abs(stat.st_atime - t) < 1
def test_version(ctx): files = """ - package.json: | { "version": "1.1.2" } """ with create_files(files) as directory: assert version.version(ctx.init()) == '1.1.2'
def test_create_directory(): fdef = """ bar: - foo.txt """ with create_files(fdef, cleanup=True) as workdir: print "WORKDIR:", workdir print tree(workdir) assert tree(workdir) == [os.path.join(workdir, 'bar', 'foo.txt')]
def test_copy(ctx): files = """ foo.txt: hello world """ with create_files(files) as directory: ctx = ctx.init() copy(ctx, 'foo.txt', 'foo.txt') copy(ctx, 'foo.txt', 'bar.txt') assert open('bar.txt').read() == 'hello world'
def test_version(): files = """ setup.py: | from distutils.core import setup setup(version='1.1.2') """ with create_files(files) as directory: pkg = package.Package() assert pkg.version == '1.1.2'
def test_empty_directory2(): fdef = """ bar: [] """ with create_files(fdef, cleanup=True) as workdir: print "WORKDIR:", workdir print tree(workdir) bardir = os.path.join(workdir, 'bar') assert os.path.isdir(bardir) assert os.listdir(bardir) == []
def test_contains(): files = """ - a - b """ with create_files(files) as _root: root = path.Path(_root) assert 'a' in root assert 'b' in root assert 'c' not in root
def test_create_file(): fdef = """ foo.txt """ with create_files(fdef, cleanup=True) as workdir: print "WORKDIR:", workdir print tree(workdir) assert tree(workdir) == [os.path.join(workdir, 'foo.txt')] assert os.path.isfile('foo.txt') assert open('foo.txt').read() == ""
def test_version(): files = """ - package.ini: | [package] version = 1.1.2 """ with create_files(files) as directory: # os.chdir(directory) pkg = package.Package() assert pkg.version == '1.1.2'
def test_multifiles(): files = """ a: - b: | hello - c: | world """ with create_files(files) as directory: assert changed.changed('a') assert not Directory('a').changed()
def test_version(): files = """ - package.json: | { "version": "1.1.2" } """ with create_files(files) as directory: os.chdir(directory) pkg = package.Package() assert pkg.version == '1.1.2'
def test_cd_contextmanager(): files = """ a: - b """ with create_files(files) as _root: root = path.Path(_root) assert 'a' in os.listdir('.') with (root/'a').cd(): assert 'b' in os.listdir('.') assert 'a' in os.listdir('.')
def test_find_package2(): files = """ - package.ini: | [package] version = 1.1.2 - subdir: - empty """ with create_files(files) as directory: os.chdir(os.path.join(directory, 'subdir')) pkg = package.Package(directory) assert pkg.version == '1.1.2'
def test_attributes(): files = """ - package.json: | { "version": "1.1.2" } """ with create_files(files) as directory: os.chdir(directory) pkg = package.Package() assert pkg.version == '1.1.2' assert pkg.get('foo', 'bar') == 'bar' with pytest.raises(AttributeError): pkg.foo
def test_create_empty_files(): fdef = """ - foo.txt - bar.txt """ with create_files(fdef, cleanup=True) as workdir: print "WORKDIR:", workdir print tree(workdir) assert tree(workdir) == [ os.path.join(workdir, 'bar.txt'), os.path.join(workdir, 'foo.txt') ]
def test_attributes(): files = """ setup.py: | from distutils.core import setup setup(version='1.1.2') """ with create_files(files) as directory: assert dktasklib.package.setup_file.SetupPy.exists() pkg = package.Package() assert pkg.version == '1.1.2' assert pkg.get('foo', 'bar') == 'bar' with pytest.raises(AttributeError): pkg.foo
def test_find_package(): files = """ setup.py: | from distutils.core import setup setup(version='1.1.2') subdir: [] """ with create_files(files) as directory: print "\nCURDIR:", os.getcwd() print "CONTENTS:", os.listdir('.') os.chdir('subdir') pkg = package.Package() assert pkg.version == '1.1.2'
def test_find_package(): files = """ - package.json: | { "version": "1.1.2" } - subdir: - empty """ with create_files(files) as directory: os.chdir(os.path.join(directory, 'subdir')) pkg = package.Package() assert pkg.version == '1.1.2'
def test_line_endings(): files = """ foo.txt """ with create_files(files) as directory: with open('foo.txt', 'wb') as fp: fp.write("a\nb\r\nc\nd\n") print repr(open('foo.txt', 'rb').read()) assert len(line_endings('foo.txt')) == 2 fix_line_endings('foo.txt') assert len(line_endings('foo.txt')) == 1
def test_add_version_hash(ctx): files = """ - package.json: | { "version": "1.1.2" } - foo.txt """ with create_files(files) as directory: version.copy_to_version( ctx.init(pkg=Package()), 'foo.txt', kind='hash' ) print os.listdir('.') assert len(os.listdir('.')) == 3
def test_iter(): files = """ - .dotfile - .dotdir: - d - e - a - b - c: - d """ with create_files(files) as _root: root = path.Path(_root) assert _relcontent(root) == {'a', 'b', opjoin('c', 'd')}
def test_attributes(): files = """ - package.ini: | [package] version = 1.1.2 """ with create_files(files) as directory: # os.chdir(directory) assert dktasklib.package.package_ini.PackageIni.exists() pkg = package.Package() assert pkg.version == '1.1.2' assert pkg.get('foo', 'bar') == 'bar' with pytest.raises(AttributeError): pkg.foo
def test_lessc(ctx): files = """ foo.less: | .foo { display: flex; } """ with create_files(files) as directory: print lessc.lessc( ctx.init(), src='foo.less', dst='foo.css', autoprefix="ie > 8, last 4 versions" ) assert 'foo.css' in os.listdir('.') print open('foo.css').read() assert len(open('foo.css').read()) > len(open('foo.less').read())
def test_marker(): from yamldirs import create_files from vpip.commands.install import install_local_first_time from vpip.commands.update import update_local from vpip import pip_api, venv files = """ requirements.txt: | twine~=3.0; python_version < '3' """ with create_files(files): install_local_first_time() with venv.get_current_venv().activate(): assert all(r.name != "twine" for r in pip_api.list_()) update_local([]) assert all(r.name != "twine" for r in pip_api.list_())
def test_subdirs(): files = """ - a.py - b: - a.txt - aa.txt - d - e: - a: - b - f """ with create_files(files) as _root: root = path.Path(_root) assert [d.relpath(root) for d in root.subdirs()] == ['b', 'e']
def test_concat(ctx): files = """ - foo.txt - bar.txt """ with create_files(files) as directory: with open('foo.txt', 'wb') as fp: fp.write('a\r\n') with open('bar.txt', 'wb') as fp: fp.write('b\n') print "LISTDIR", os.listdir('.') print "FOO:", `open('foo.txt', 'rb').read()` print "BAR:", `open('bar.txt', 'rb').read()` concat(ctx.init(), 'baz.txt', 'foo.txt', 'bar.txt', force=True) print "BAZ:", `open('baz.txt', 'rb').read()` assert open('baz.txt').read().split() == ['a', 'b']
def test_create_files(): fdef = """ - foo.txt: | hello - bar.txt: | world """ with create_files(fdef, cleanup=True) as workdir: print "WORKDIR:", workdir print tree(workdir) assert tree(workdir) == [ os.path.join(workdir, 'bar.txt'), os.path.join(workdir, 'foo.txt') ] assert open(os.path.join(workdir, 'foo.txt')).read() == 'hello\n' assert open(os.path.join(workdir, 'bar.txt')).read() == 'world\n'
def test_nested_directory(): fdef = """ foo: - a - bar: - b """ with create_files(fdef, cleanup=True) as workdir: print "WORKDIR:", workdir print tree(workdir) foodir = os.path.join(workdir, 'foo') bardir = os.path.join(workdir, 'foo', 'bar') assert os.path.isdir(foodir) assert os.path.isdir(bardir) assert set(os.listdir(foodir)) == {'a', 'bar'} assert os.listdir(bardir) == ['b']
def test_unlink(): files = """ - a - b """ with create_files(files) as _root: root = path.Path(_root) assert {p.relpath(root) for p in root} == {'a', 'b'} b = root / 'b' b.unlink() assert [p.relpath(root) for p in root] == ['a'] a = root / 'a' a.remove() assert [p.relpath(root) for p in root] == []
def test_sub_deps_conflict(): from yamldirs import create_files from vpip.commands.install import install_local_first_time from vpip.commands.update import update_local from vpip import pip_api, venv files = """ requirements.txt: | Sphinx~=4.0 twine~=3.0 """ with create_files(files): install_local_first_time() with venv.get_current_venv().activate(): update_local(["twine~=4.0"]) docutils, = pip_api.show(["docutils"]) assert docutils.version.startswith("0.17")
def test_commonprefix(): files = """ - a.py - b: - a.txt - aa.txt - d - e: - a: - b - f """ with create_files(files) as _root: root = path.Path(_root) assert root.commonprefix(root) == root assert root.commonprefix(root/'a.py', root/'d', root/'b'/'a.txt') == root
def test_rmtree(): files = """ a: b: c: d.txt: hello world e: f.txt: thanks for all the fish """ with create_files(files) as _root: root = path.Path(_root) print "FILES:", root.contents() # print "LISTALL:", root.listall() (root / 'a').rmtree('b') assert root.contents() == [path.Path('e') / 'f.txt'] (root / 'e').rmtree() assert root.contents() == []
def test_chmod(): files = """ a """ with create_files(files) as _root: root = path.Path(_root) (root / 'a').chmod(00400) # only read for only current user # (root / 'a').chmod(stat.S_IREAD) if sys.platform == 'win32': # doesn't appear to be any way for a user to create a file that he # can't unlink on linux. with pytest.raises(OSError): (root / 'a').unlink() assert root.listdir() == ['a'] (root / 'a').chmod(stat.S_IWRITE) (root / 'a').unlink() assert root.listdir() == []
def test_mix_empty(): files = """ - a.py - b: - a.txt - aa.txt - d - e: - a: - b - f """ with create_files(files) as workdir: print "WORKDIR:", workdir print tree(workdir) print "LISTDIR:", os.listdir('.') assert {os.path.relpath(d, workdir) for d in os.listdir('.')} == {'a.py', 'b', 'd', 'e', 'f'}
def test_files(): files = """ - a.py - b: - a.txt - aa.txt - d - e: - a: - b - f """ with create_files(files) as _root: root = path.Path(_root) print "LISTDIR:", os.listdir('.') assert {d.relpath(root) for d in root.files()} == { 'a.py', 'd', 'f' }
def init_dirs(config): gomap_dir = config["input"]["workdir"] + "/GOMAP-" + config["input"][ "basename"] config["input"]["gomap_dir"] = gomap_dir if not os.path.exists(gomap_dir): os.makedirs(gomap_dir, mode=0777) excl_files = ['a'] for root, dir, files in os.walk(gomap_dir): excl_files = excl_files + files with open(config["pipeline"]["dir_struct"]) as tmp_file: dir_struct = tmp_file.read() with create_files(dir_struct) as workdir: results = pyrocopy.copy(workdir, gomap_dir, excludeFiles=excl_files, detailedResults=True) setlogging(config, "init_dirs") logging.info("Initializing directory structure") logging.info(pformat(results)) return (config)
def test_create_file_multiline_content(): fdef = """ foo.txt: | Lorem ipsum dolor sit amet, vis no altera doctus sanctus, oratio euismod suscipiantur ne vix, no duo inimicus adversarium. Et amet errem vis. Aeterno accusamus sed ei, id eos inermis epicurei. Quo enim sonet iudico ea, usu et possit euismod. """ lorem = textwrap.dedent("""\ Lorem ipsum dolor sit amet, vis no altera doctus sanctus, oratio euismod suscipiantur ne vix, no duo inimicus adversarium. Et amet errem vis. Aeterno accusamus sed ei, id eos inermis epicurei. Quo enim sonet iudico ea, usu et possit euismod. """) with create_files(fdef, cleanup=True) as workdir: print "WORKDIR:", workdir print tree(workdir) assert tree(workdir) == [os.path.join(workdir, 'foo.txt')] assert open(os.path.join(workdir, 'foo.txt')).read() == lorem