repo stringclasses 454
values | file_path stringlengths 5 201 | extension stringclasses 1
value | content stringlengths 8 509k | num_lines int64 3 16.9k | size_bytes int64 8 511k |
|---|---|---|---|---|---|
funcy | setup.py | .py | from setuptools import setup
# Remove build status
README = open('README.rst').read().replace('|Build Status|', '', 1)
setup(
name='funcy',
version=open('VERSION').read().strip(),
author='Alexander Schepanovski',
author_email='suor.web@gmail.com',
description='A fancy and practical functional t... | 45 | 1,505 |
funcy | funcy/seqs.py | .py | import sys
from itertools import islice, chain, tee, groupby, filterfalse, accumulate, \
takewhile as _takewhile, dropwhile as _dropwhile
from collections.abc import Sequence
from collections import defaultdict, deque
import operator
from .primitives import EMPTY
from .types import is_seqcont
fro... | 505 | 15,340 |
funcy | funcy/types.py | .py | from collections.abc import Mapping, Set, Sequence, Iterator, Iterable
__all__ = ('isa', 'is_mapping', 'is_set', 'is_seq', 'is_list', 'is_tuple',
'is_seqcoll', 'is_seqcont',
'iterable', 'is_iter')
def isa(*types):
"""
Creates a function checking if its argument
is of any of given t... | 27 | 614 |
funcy | funcy/strings.py | .py | import re
from operator import methodcaller
from .primitives import EMPTY
__all__ = ['re_iter', 're_all', 're_find', 're_finder', 're_test', 're_tester',
'str_join',
'cut_prefix', 'cut_suffix']
def _make_getter(regex):
if regex.groups == 0:
return methodcaller('group')
elif re... | 79 | 2,452 |
funcy | funcy/funcolls.py | .py | from .funcs import compose, juxt
from .colls import some, none, one
__all__ = ['all_fn', 'any_fn', 'none_fn', 'one_fn', 'some_fn']
def all_fn(*fs):
"""Constructs a predicate, which holds when all fs hold."""
return compose(all, juxt(*fs))
def any_fn(*fs):
"""Constructs a predicate, which holds when any... | 28 | 775 |
funcy | funcy/objects.py | .py | from inspect import isclass, ismodule
from .strings import cut_prefix
__all__ = ['cached_property', 'cached_readonly', 'wrap_prop', 'monkey', 'LazyObject']
class cached_property(object):
"""
Decorator that converts a method with a single self argument into
a property cached on the instance.
"""
... | 108 | 3,155 |
funcy | funcy/colls.py | .py | from builtins import all as _all, any as _any
from copy import copy
from operator import itemgetter, methodcaller, attrgetter
from itertools import chain, tee
from collections import defaultdict
from collections.abc import Mapping, Set, Iterable, Iterator
from .primitives import EMPTY
from .funcs import partial, compo... | 375 | 11,816 |
funcy | funcy/funcs.py | .py | from operator import __not__
from functools import partial, reduce, wraps
from ._inspect import get_spec, Spec
from .primitives import EMPTY
from .funcmakers import make_func, make_pred
__all__ = ['identity', 'constantly', 'caller',
# reexport functools for convenience
'reduce', 'partial',
... | 138 | 4,403 |
funcy | funcy/debug.py | .py | import re
import traceback
from itertools import chain
from functools import partial
from timeit import default_timer as timer
from .decorators import decorator, wraps, Call
__all__ = [
'tap',
'log_calls', 'print_calls',
'log_enters', 'print_enters',
'log_exits', 'print_exits',
'log_errors', 'pri... | 244 | 7,675 |
funcy | funcy/_inspect.py | .py | from __future__ import absolute_import
from inspect import CO_VARARGS, CO_VARKEYWORDS, signature
from collections import namedtuple
import platform
import re
from .decorators import unwrap
IS_PYPY = platform.python_implementation() == "PyPy"
# This provides sufficient introspection for *curry() functions.
#
# We on... | 187 | 6,352 |
funcy | funcy/tree.py | .py | from collections import deque
from .types import is_seqcont
__all__ = ['tree_leaves', 'ltree_leaves', 'tree_nodes', 'ltree_nodes']
def tree_leaves(root, follow=is_seqcont, children=iter):
"""Iterates over tree leaves."""
q = deque([[root]])
while q:
node_iter = iter(q.pop())
for sub in n... | 41 | 1,130 |
funcy | funcy/decorators.py | .py | from contextlib import ContextDecorator, contextmanager # reexport these for backwards compat
import functools
from inspect import unwrap # reexport this for backwards compat
import inspect
from . colls import omit
__all__ = ['decorator', 'wraps', 'unwrap', 'ContextDecorator', 'contextmanager']
def decorator(deco... | 185 | 6,288 |
funcy | funcy/funcmakers.py | .py | from collections.abc import Mapping, Set
from operator import itemgetter
from .strings import re_tester, re_finder, _re_type
__all__ = ('make_func', 'make_pred')
def make_func(f, test=False):
if callable(f):
return f
elif f is None:
# pass None to builtin as predicate or mapping function fo... | 29 | 809 |
funcy | funcy/flow.py | .py | from collections.abc import Hashable
from datetime import datetime, timedelta
import time
import threading
from contextlib import suppress # reexport
from .decorators import decorator, wraps, get_argnames, arggetter, contextmanager
__all__ = ['raiser', 'ignore', 'silent', 'suppress', 'nullcontext', 'reraise', 'retr... | 247 | 7,282 |
funcy | funcy/primitives.py | .py | __all__ = ['isnone', 'notnone', 'inc', 'dec', 'even', 'odd']
class EmptyType:
def __repr__(self):
return 'EMPTY'
EMPTY = EmptyType() # Used as unique default for optional arguments
def isnone(x):
return x is None
def notnone(x):
return x is not None
def inc(x):
return x + 1
def dec(x):
... | 29 | 408 |
funcy | funcy/calc.py | .py | from datetime import timedelta
import time
import inspect
from collections import deque
from bisect import bisect
from .decorators import wraps
__all__ = ['memoize', 'make_lookuper', 'silent_lookuper', 'cache']
class SkipMemory(Exception):
pass
# TODO: use pos-only arg once in Python 3.8+ only
def memoize(_... | 153 | 4,673 |
funcy | tests/test_tree.py | .py | from whatever import _
from funcy import rest
from funcy.tree import *
def test_tree_leaves():
assert ltree_leaves([1, 2, [3, [4]], 5]) == [1, 2, 3, 4, 5]
assert ltree_leaves(1) == [1]
assert ltree_leaves(3, follow=_ > 1, children=range) == [0, 1, 0, 1]
assert ltree_leaves([1, [2, [3, 4], 5], 6], ch... | 24 | 619 |
funcy | tests/py38_decorators.py | .py | import pytest
from funcy.decorators import decorator
def test_decorator_access_args():
@decorator
def return_x(call):
return call.x
# no arg
with pytest.raises(AttributeError): return_x(lambda y: None)(10)
# pos arg
assert return_x(lambda x: None)(10) == 10
with pytest.raises(Att... | 43 | 1,540 |
funcy | tests/test_debug.py | .py | import re
from funcy.debug import *
from funcy.flow import silent
from funcy.seqs import lmap
def test_tap():
assert capture(tap, 42) == '42\n'
assert capture(tap, 42, label='Life and ...') == 'Life and ...: 42\n'
def test_log_calls_keyword():
log = []
@log_calls(log.append)
def f(x, y=2):
... | 183 | 4,062 |
funcy | tests/test_funcs.py | .py | from operator import __add__, __sub__
import sys
import pytest
from whatever import _
from funcy import lmap, merge_with
from funcy.funcs import *
from funcy.seqs import keep
def test_caller():
assert caller([1, 2])(sum) == 3
def test_constantly():
assert constantly(42)() == 42
assert constantly(42)('hi... | 201 | 6,281 |
funcy | tests/test_colls.py | .py | from collections.abc import Iterator
from collections import defaultdict, namedtuple
from itertools import chain, count
import pytest
from whatever import _
from funcy.colls import *
# Utilities
def eq(a, b):
return type(a) is type(b) and a == b \
and (a.default_factory == b.default_factory if isinstance(... | 357 | 10,391 |
funcy | tests/test_funcmakers.py | .py | from collections import defaultdict
import pytest
from funcy.funcmakers import *
def test_callable():
assert make_func(lambda x: x + 42)(0) == 42
def test_int():
assert make_func(0)('abc') == 'a'
assert make_func(2)([1,2,3]) == 3
assert make_func(1)({1: 'a'}) == 'a'
with pytest.raises(IndexErro... | 43 | 993 |
funcy | tests/py38_funcs.py | .py | import pytest
from funcy.funcs import autocurry
def test_autocurry_posonly():
at = autocurry(lambda a, /, b: (a, b))
assert at(1)(b=2) == (1, 2)
assert at(b=2)(1) == (1, 2)
with pytest.raises(TypeError): at(a=1)(b=2)
at = autocurry(lambda a, /, **kw: (a, kw))
assert at(a=2)(1) == (1, {'a': 2}... | 17 | 432 |
funcy | tests/test_strings.py | .py | from funcy.strings import *
def test_re_find():
assert re_find(r'\d+', 'x34y12') == '34'
assert re_find(r'y(\d+)', 'x34y12') == '12'
assert re_find(r'([a-z]+)(\d+)', 'x34y12') == ('x', '34')
assert re_find(r'(?P<l>[a-z]+)(?P<d>\d+)', 'x34y12') == {'l': 'x', 'd': '34'}
def test_re_all():
assert r... | 30 | 982 |
funcy | tests/test_seqs.py | .py | from collections.abc import Iterator
from operator import add
import pytest
from whatever import _
from funcy import is_list
from funcy.seqs import *
def test_repeatedly():
counter = count()
c = lambda: next(counter)
assert take(2, repeatedly(c)) == [0, 1]
def test_iterate():
assert take(4, iterate(... | 220 | 7,072 |
funcy | tests/test_interface.py | .py | import funcy
def test_docs():
exports = [(name, getattr(funcy, name)) for name in funcy.__all__
if name not in ('print_errors', 'print_durations', 'ErrorRateExceeded')
and getattr(funcy, name).__module__ not in ('funcy.types', 'funcy.primitives')]
# NOTE: we are testing thi... | 11 | 543 |
funcy | tests/test_objects.py | .py | import sys
import pytest
from funcy.objects import *
from funcy import suppress
### @cached_property
def test_cached_property():
calls = [0]
class A(object):
@cached_property
def prop(self):
calls[0] += 1
return 7
a = A()
assert a.prop == 7
assert a.prop ... | 157 | 2,799 |
funcy | tests/test_decorators.py | .py | import sys
import pytest
from funcy.decorators import *
def test_decorator_no_args():
@decorator
def inc(call):
return call() + 1
@inc
def ten():
return 10
assert ten() == 11
def test_decorator_with_args():
@decorator
def add(call, n):
return call() + n
@ad... | 168 | 3,475 |
funcy | tests/test_flow.py | .py | from datetime import timedelta
import pytest
from funcy.flow import *
def test_silent():
assert silent(int)(1) == 1
assert silent(int)('1') == 1
assert silent(int)('hello') is None
assert silent(str.upper)('hello') == 'HELLO'
class MyError(Exception):
pass
def test_ignore():
assert ignore... | 262 | 5,718 |
funcy | tests/test_calc.py | .py | from math import sin, cos
from datetime import timedelta
import pytest
from funcy.calc import *
def test_memoize():
@memoize
def inc(x):
calls.append(x)
return x + 1
calls = []
assert inc(0) == 1
assert inc(1) == 2
assert inc(0) == 1
assert calls == [0, 1]
# using kw... | 201 | 4,086 |
funcy | tests/test_types.py | .py | from funcy.types import *
def test_iterable():
assert iterable([])
assert iterable({})
assert iterable('abc')
assert iterable(iter([]))
assert iterable(x for x in range(10))
assert iterable(range(10))
assert not iterable(1)
def test_is_iter():
assert is_iter(iter([]))
assert is_... | 21 | 409 |
funcy | tests/test_funcolls.py | .py | from whatever import _
from funcy import lfilter
from funcy.funcolls import *
def test_all_fn():
assert lfilter(all_fn(_ > 3, _ % 2), range(10)) == [5, 7, 9]
def test_any_fn():
assert lfilter(any_fn(_ > 3, _ % 2), range(10)) == [1, 3, 4, 5, 6, 7, 8, 9]
def test_none_fn():
assert lfilter(none_fn(_ > 3, ... | 29 | 640 |
slimit | setup.py | .py | import os, sys
from setuptools import setup, find_packages
try:
from distutils.command.build_py import build_py_2to3 as build_py
except ImportError:
from distutils.command.build_py import build_py
classifiers = """\
Intended Audience :: Developers
License :: OSI Approved :: MIT License
Programming Language :: ... | 58 | 1,651 |
slimit | src/slimit/parser.py | .py | ###############################################################################
#
# Copyright (c) 2011 Ruslan Spivak
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, inc... | 1,224 | 40,155 |
slimit | src/slimit/scope.py | .py | ###############################################################################
#
# Copyright (c) 2011 Ruslan Spivak
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, inc... | 184 | 5,626 |
slimit | src/slimit/minifier.py | .py | ###############################################################################
#
# Copyright (c) 2011 Ruslan Spivak
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, inc... | 71 | 2,652 |
slimit | src/slimit/ast.py | .py | ###############################################################################
#
# Copyright (c) 2011 Ruslan Spivak
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, inc... | 416 | 10,841 |
slimit | src/slimit/lexer.py | .py | ###############################################################################
#
# Copyright (c) 2011 Ruslan Spivak
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, inc... | 448 | 15,253 |
slimit | src/slimit/mangler.py | .py | ###############################################################################
#
# Copyright (c) 2011 Ruslan Spivak
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, inc... | 52 | 1,906 |
slimit | src/slimit/lextab.py | .py | # coding=utf-8
# lextab.py. This file automatically created by PLY (version 3.11). Don't edit!
_tabversion = '3.10'
_lextokens = set(('AND', 'ANDEQUAL', 'BAND', 'BLOCK_COMMENT', 'BNOT', 'BOR', 'BREAK', 'BXOR', 'CASE', 'CATCH', 'CLASS', 'COLON', 'COMMA', 'CONDOP', 'CONST', 'CONTINUE', 'DEBUGGER', 'DEFAULT', 'DELETE... | 12 | 18,320 |
slimit | src/slimit/unicode_chars.py | .py | ###############################################################################
#
# Copyright (c) 2011 Ruslan Spivak
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, inc... | 155 | 9,745 |
slimit | src/slimit/visitors/nodevisitor.py | .py | ###############################################################################
#
# Copyright (c) 2011 Ruslan Spivak
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, inc... | 87 | 2,877 |
slimit | src/slimit/visitors/ecmavisitor.py | .py | ###############################################################################
#
# Copyright (c) 2011 Ruslan Spivak
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, inc... | 398 | 12,757 |
slimit | src/slimit/visitors/minvisitor.py | .py | ###############################################################################
#
# Copyright (c) 2011 Ruslan Spivak
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, inc... | 438 | 14,179 |
slimit | src/slimit/visitors/scopevisitor.py | .py | ###############################################################################
#
# Copyright (c) 2011 Ruslan Spivak
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, inc... | 200 | 6,754 |
slimit | src/slimit/tests/test_parser.py | .py | ###############################################################################
#
# Copyright (c) 2011-2012 Ruslan Spivak
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction... | 244 | 5,995 |
slimit | src/slimit/tests/test_lexer.py | .py | ###############################################################################
# encoding: utf-8
#
# Copyright (c) 2011 Ruslan Spivak
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software withou... | 298 | 13,099 |
slimit | src/slimit/tests/test_cmd.py | .py | ###############################################################################
#
# Copyright (c) 2011 Ruslan Spivak
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, inc... | 119 | 3,941 |
slimit | src/slimit/tests/test_mangler.py | .py | ###############################################################################
#
# Copyright (c) 2011 Ruslan Spivak
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, inc... | 160 | 4,699 |
slimit | src/slimit/tests/test_minifier.py | .py | ###############################################################################
#
# Copyright (c) 2011 Ruslan Spivak
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, inc... | 471 | 14,736 |
slimit | src/slimit/tests/test_ecmavisitor.py | .py | ###############################################################################
#
# Copyright (c) 2011 Ruslan Spivak
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, inc... | 506 | 10,717 |
pyfilesystem2 | setup.py | .py | #!/usr/bin/env python
import os
with open(os.path.join("fs", "_version.py")) as f:
exec(f.read())
from setuptools import setup
setup(version=__version__)
| 11 | 162 |
pyfilesystem2 | tests/test_imports.py | .py | import sys
import unittest
class TestImports(unittest.TestCase):
def test_import_path(self):
"""Test import fs also imports other symbols."""
restore_fs = sys.modules.pop("fs")
sys.modules.pop("fs.path")
try:
import fs
fs.path
fs.Seek
... | 20 | 422 |
pyfilesystem2 | tests/test_subfs.py | .py | from __future__ import unicode_literals
import os
import shutil
import tempfile
import unittest
from fs import osfs
from fs.memoryfs import MemoryFS
from fs.path import relpath
from fs.subfs import SubFS
from .test_osfs import TestOSFS
class TestSubFS(TestOSFS):
"""Test OSFS implementation."""
def setUp(s... | 74 | 1,927 |
pyfilesystem2 | tests/test_opener.py | .py | from __future__ import unicode_literals
import sys
import os
import pkg_resources
import shutil
import tempfile
import unittest
from fs import open_fs, opener
from fs.appfs import UserDataFS
from fs.memoryfs import MemoryFS
from fs.opener import errors, registry
from fs.opener.parse import ParseResult
from fs.opener... | 338 | 11,892 |
pyfilesystem2 | tests/test_mountfs.py | .py | from __future__ import unicode_literals
import unittest
from fs.memoryfs import MemoryFS
from fs.mountfs import MountError, MountFS
from fs.tempfs import TempFS
from fs.test import FSTestCases
class TestMountFS(FSTestCases, unittest.TestCase):
"""Test OSFS implementation."""
def make_fs(self):
fs =... | 93 | 2,686 |
pyfilesystem2 | tests/test_tree.py | .py | from __future__ import print_function, unicode_literals
import io
import unittest
from fs import tree
from fs.memoryfs import MemoryFS
class TestInfo(unittest.TestCase):
def setUp(self):
self.fs = MemoryFS()
self.fs.makedir("foo")
self.fs.makedir("bar")
self.fs.makedir("baz")
... | 79 | 4,759 |
pyfilesystem2 | tests/test_new_name.py | .py | from __future__ import unicode_literals
import unittest
import warnings
from fs.base import _new_name
class TestNewNameDecorator(unittest.TestCase):
def double(self, n):
"Double a number"
return n * 2
times_2 = _new_name(double, "times_2")
def test_old_name(self):
"""Test _new_... | 28 | 791 |
pyfilesystem2 | tests/test_wrap.py | .py | from __future__ import unicode_literals
import operator
import unittest
try:
from unittest import mock
except ImportError:
import mock
import six
import fs.copy
import fs.errors
import fs.mirror
import fs.move
import fs.wrap
from fs import open_fs
from fs.info import Info
class TestWrapReadOnly(unittest.T... | 220 | 7,991 |
pyfilesystem2 | tests/test_tarfs.py | .py | # -*- encoding: UTF-8
from __future__ import unicode_literals
import io
import os
import six
import tarfile
import tempfile
import unittest
from fs import tarfs
from fs.compress import write_tar
from fs.enums import ResourceType
from fs.errors import NoURL
from fs.opener import open_fs
from fs.opener.errors import No... | 318 | 9,770 |
pyfilesystem2 | tests/test_encoding.py | .py | from __future__ import unicode_literals
import os
import platform
import shutil
import six
import tempfile
import unittest
import fs
from fs.osfs import OSFS
if platform.system() != "Windows":
@unittest.skipIf(platform.system() == "Darwin", "Bad unicode not possible on OSX")
class TestEncoding(unittest.Test... | 58 | 2,151 |
pyfilesystem2 | tests/test_errors.py | .py | from __future__ import unicode_literals
import multiprocessing
import unittest
from six import text_type
from fs import errors
from fs.errors import CreateFailed
class TestErrors(unittest.TestCase):
def test_str(self):
err = errors.FSError("oh dear")
repr(err)
self.assertEqual(text_type(... | 65 | 1,910 |
pyfilesystem2 | tests/test_filesize.py | .py | from __future__ import unicode_literals
import unittest
from fs import filesize
class TestFilesize(unittest.TestCase):
def test_traditional(self):
self.assertEqual(filesize.traditional(0), "0 bytes")
self.assertEqual(filesize.traditional(1), "1 byte")
self.assertEqual(filesize.tradition... | 52 | 1,666 |
pyfilesystem2 | tests/test_url_tools.py | .py | # coding: utf-8
"""Test url tools. """
from __future__ import unicode_literals
import platform
import unittest
from fs._url_tools import url_quote
class TestBase(unittest.TestCase):
def test_quote(self):
test_fixtures = [
# test_snippet, expected
["foo/bar/egg/foofoo", "foo/bar/e... | 40 | 1,370 |
pyfilesystem2 | tests/test_glob.py | .py | from __future__ import unicode_literals
import re
import unittest
from parameterized import parameterized
from fs import glob, open_fs
class TestGlob(unittest.TestCase):
def setUp(self):
fs = self.fs = open_fs("mem://")
fs.writetext("foo.py", "Hello, World")
fs.touch("bar.py")
f... | 151 | 6,224 |
pyfilesystem2 | tests/test_zipfs.py | .py | # -*- encoding: UTF-8
from __future__ import unicode_literals
import sys
import os
import six
import tempfile
import unittest
import zipfile
from fs import zipfs
from fs.compress import write_zip
from fs.enums import Seek
from fs.errors import NoURL
from fs.opener import open_fs
from fs.opener.errors import NotWrite... | 227 | 7,792 |
pyfilesystem2 | tests/test_tempfs.py | .py | from __future__ import unicode_literals
import os
from fs import errors
from fs.tempfs import TempFS
from .test_osfs import TestOSFS
try:
from unittest import mock
except ImportError:
import mock
class TestTempFS(TestOSFS):
"""Test OSFS implementation."""
def make_fs(self):
return TempFS(... | 36 | 829 |
pyfilesystem2 | tests/test_doctest.py | .py | # coding: utf-8
"""Test doctest contained tests in every file of the module.
"""
import doctest
import importlib
import os
import pkgutil
import tempfile
import time
import types
import unittest
import warnings
from pprint import pprint
try:
from unittest import mock
except ImportError:
import mock
import six... | 195 | 6,233 |
pyfilesystem2 | tests/test_iotools.py | .py | from __future__ import unicode_literals
import io
import six
import unittest
from fs import iotools, tempfs
from fs.test import UNICODE_TEXT
class TestIOTools(unittest.TestCase):
def setUp(self):
self.fs = tempfs.TempFS("iotoolstest")
def tearDown(self):
self.fs.close()
del self.fs
... | 157 | 5,357 |
pyfilesystem2 | tests/test_osfs.py | .py | # coding: utf-8
from __future__ import unicode_literals
import sys
import errno
import io
import os
import shutil
import tempfile
import time
import unittest
import warnings
from six import text_type
from fs import errors, open_fs, osfs
from fs.path import dirname, relpath
from fs.test import FSTestCases
try:
f... | 231 | 8,053 |
pyfilesystem2 | tests/test_archives.py | .py | # -*- encoding: UTF-8
from __future__ import unicode_literals
import os
import stat
from six import text_type
from fs import errors, walk
from fs.enums import ResourceType
from fs.opener import open_fs
from fs.test import UNICODE_TEXT
class ArchiveTestCases(object):
def make_source_fs(self):
return open... | 137 | 4,451 |
pyfilesystem2 | tests/test_error_tools.py | .py | from __future__ import unicode_literals
import errno
import unittest
import fs.errors
from fs.error_tools import convert_os_errors
class TestErrorTools(unittest.TestCase):
def test_convert_enoent(self):
exception = OSError(errno.ENOENT, "resource not found")
with self.assertRaises(fs.errors.Reso... | 26 | 924 |
pyfilesystem2 | tests/test_memoryfs.py | .py | from __future__ import unicode_literals
import posixpath
import unittest
from fs import memoryfs
from fs.test import UNICODE_TEXT, FSTestCases
try:
# Only supported on Python 3.4+
import tracemalloc
except ImportError:
tracemalloc = None
class TestMemoryFS(FSTestCases, unittest.TestCase):
"""Test O... | 97 | 2,997 |
pyfilesystem2 | tests/test_info.py | .py | from __future__ import unicode_literals
import unittest
from datetime import datetime
from fs.enums import ResourceType
from fs.info import Info
from fs.permissions import Permissions
from fs.time import datetime_to_epoch
try:
from datetime import timezone
except ImportError:
from fs._tzcompat import timezon... | 133 | 4,581 |
pyfilesystem2 | tests/test_permissions.py | .py | from __future__ import print_function, unicode_literals
import unittest
from six import text_type
from fs.permissions import Permissions, make_mode
class TestPermissions(unittest.TestCase):
def test_make_mode(self):
self.assertEqual(make_mode(None), 0o777)
self.assertEqual(make_mode(0o755), 0o75... | 134 | 4,692 |
pyfilesystem2 | tests/test_bulk.py | .py | from __future__ import unicode_literals
import unittest
from fs._bulk import Copier, _Task
from fs.errors import BulkCopyFailed
class BrokenTask(_Task):
def __call__(self):
1 / 0
class TestBulk(unittest.TestCase):
def test_worker_error(self):
with self.assertRaises(BulkCopyFailed):
... | 19 | 410 |
pyfilesystem2 | tests/test_wrapfs.py | .py | from __future__ import unicode_literals
import unittest
from six import text_type
from fs import wrapfs
from fs.opener import open_fs
class WrappedFS(wrapfs.WrapFS):
wrap_name = "test"
class TestWrapFS(unittest.TestCase):
def setUp(self):
self.wrapped_fs = open_fs("mem://")
self.fs = Wrapp... | 30 | 853 |
pyfilesystem2 | tests/test_multifs.py | .py | from __future__ import unicode_literals
import unittest
from fs import errors
from fs.memoryfs import MemoryFS
from fs.multifs import MultiFS
from fs.test import FSTestCases
class TestMultiFS(FSTestCases, unittest.TestCase):
"""Test OSFS implementation."""
def setUp(self):
fs = MultiFS()
me... | 140 | 4,424 |
pyfilesystem2 | tests/test_path.py | .py | from __future__ import absolute_import, print_function, unicode_literals
"""
fstests.test_path: testcases for the fs path functions
"""
import unittest
from fs.path import (
abspath,
basename,
combine,
dirname,
forcedir,
frombase,
isabs,
isbase,
isdotfile,
isparent,
i... | 227 | 7,655 |
pyfilesystem2 | tests/test_appfs.py | .py | from __future__ import unicode_literals
import shutil
import six
import tempfile
import unittest
try:
from unittest import mock
except ImportError:
import mock
import fs.test
from fs import appfs
class _TestAppFS(fs.test.FSTestCases):
AppFS = None
@classmethod
def setUpClass(cls):
sup... | 87 | 1,924 |
pyfilesystem2 | tests/test_base.py | .py | """Test (abstract) base FS class."""
from __future__ import unicode_literals
import unittest
from fs import errors
from fs.base import FS
class DummyFS(FS):
def getinfo(self, path, namespaces=None):
pass
def listdir(self, path):
pass
def makedir(self, path, permissions=None, recreate=... | 66 | 1,532 |
pyfilesystem2 | tests/test_move.py | .py | from __future__ import unicode_literals
import unittest
try:
from unittest import mock
except ImportError:
import mock
from parameterized import parameterized, parameterized_class
import fs.move
from fs import open_fs
from fs.errors import FSError, ResourceReadOnly
from fs.path import join
from fs.wrap impo... | 209 | 8,991 |
pyfilesystem2 | tests/test_wildcard.py | .py | """Test f2s.fnmatch."""
from __future__ import unicode_literals
import unittest
from fs import wildcard
class TestFNMatch(unittest.TestCase):
"""Test wildcard."""
def test_wildcard(self):
self.assertTrue(wildcard.match("*.py", "file.py"))
self.assertTrue(wildcard.match("????.py", "????.py"... | 47 | 1,873 |
pyfilesystem2 | tests/test_enums.py | .py | import os
import unittest
from fs import enums
class TestEnums(unittest.TestCase):
def test_enums(self):
self.assertEqual(enums.Seek.current, os.SEEK_CUR)
self.assertEqual(enums.Seek.end, os.SEEK_END)
self.assertEqual(enums.Seek.set, os.SEEK_SET)
self.assertEqual(enums.ResourceTyp... | 13 | 334 |
pyfilesystem2 | tests/test_mode.py | .py | from __future__ import unicode_literals
import unittest
from six import text_type
from fs.mode import Mode, check_readable, check_writable
class TestMode(unittest.TestCase):
def test_checks(self):
self.assertTrue(check_readable("r"))
self.assertTrue(check_readable("r+"))
self.assertTrue(... | 50 | 1,588 |
pyfilesystem2 | tests/test_fscompat.py | .py | from __future__ import unicode_literals
import six
import unittest
from fs._fscompat import fsdecode, fsencode, fspath
class PathMock(object):
def __init__(self, path):
self._path = path
def __fspath__(self):
return self._path
class BrokenPathMock(object):
def __init__(self, path):
... | 62 | 1,563 |
pyfilesystem2 | tests/test_ftp_parse.py | .py | from __future__ import unicode_literals
import textwrap
import time
import unittest
from fs import _ftp_parse as ftp_parse
try:
from unittest import mock
except ImportError:
import mock
time2017 = time.struct_time([2017, 11, 28, 1, 1, 1, 1, 332, 0])
class TestFTPParse(unittest.TestCase):
@mock.patch("... | 355 | 13,670 |
pyfilesystem2 | tests/test_mirror.py | .py | from __future__ import unicode_literals
import unittest
from parameterized import parameterized_class
from fs import open_fs
from fs.mirror import mirror
@parameterized_class(("WORKERS",), [(0,), (1,), (2,), (4,)])
class TestMirror(unittest.TestCase):
def _contents(self, fs):
"""Extract an FS in to a si... | 113 | 3,843 |
pyfilesystem2 | tests/mark.py | .py | def slow(cls):
return cls
| 3 | 30 |
pyfilesystem2 | tests/test_walk.py | .py | from __future__ import unicode_literals
import six
import unittest
from fs import walk
from fs.errors import FSError
from fs.memoryfs import MemoryFS
from fs.wrap import read_only
class TestWalker(unittest.TestCase):
def setUp(self):
self.walker = walk.Walker()
def test_repr(self):
repr(sel... | 412 | 13,348 |
pyfilesystem2 | tests/test_ftpfs.py | .py | # coding: utf-8
from __future__ import absolute_import, print_function, unicode_literals
import calendar
import datetime
import os
import platform
import shutil
import socket
import tempfile
import time
import unittest
import uuid
try:
from unittest import mock
except ImportError:
import mock
from ftplib imp... | 395 | 13,572 |
pyfilesystem2 | tests/test_lrucache.py | .py | from __future__ import unicode_literals
import unittest
from fs import lrucache
class TestLRUCache(unittest.TestCase):
def setUp(self):
self.lrucache = lrucache.LRUCache(3)
def test_lrucache(self):
# insert some values
self.lrucache["foo"] = 1
self.lrucache["bar"] = 2
... | 33 | 862 |
pyfilesystem2 | tests/test_copy.py | .py | from __future__ import unicode_literals
import calendar
import datetime
import errno
import os
import shutil
import tempfile
import unittest
from parameterized import parameterized
import fs.copy
from fs import open_fs
def _create_sandbox_dir(prefix="pyfilesystem2_sandbox_", home=None):
if home is None:
... | 1,050 | 34,200 |
pyfilesystem2 | tests/test_tools.py | .py | from __future__ import unicode_literals
import unittest
from fs import tools
from fs.mode import validate_open_mode, validate_openbin_mode
from fs.opener import open_fs
class TestTools(unittest.TestCase):
def test_remove_empty(self):
fs = open_fs("temp://")
fs.makedirs("foo/bar/baz/egg/")
... | 56 | 1,756 |
pyfilesystem2 | tests/test_time.py | .py | from __future__ import print_function, unicode_literals
import unittest
from datetime import datetime
from fs.time import datetime_to_epoch, epoch_to_datetime
try:
from datetime import timezone
except ImportError:
from fs._tzcompat import timezone # type: ignore
class TestEpoch(unittest.TestCase):
def... | 24 | 630 |
pyfilesystem2 | examples/find_dups.py | .py | """
Find paths to files with identical contents.
Usage:
python find_dups.py <PATH or FS URL>
"""
import sys
from collections import defaultdict
from fs import open_fs
hashes = defaultdict(list)
with open_fs(sys.argv[1]) as fs:
for path in fs.walk.files():
file_hash = fs.hash(path, "md5")
... | 28 | 473 |
pyfilesystem2 | examples/rm_pyc.py | .py | """
Remove all pyc files in a directory.
Usage:
python rm_pyc.py <PATH or FS URL>
"""
import sys
from fs import open_fs
with open_fs(sys.argv[1]) as fs:
count = fs.glob("**/*.pyc").remove()
print(f"{count} .pyc files remove")
| 17 | 240 |
pyfilesystem2 | examples/upload.py | .py | """
Upload a file to a server (or other filesystem)
Usage:
python upload.py FILENAME <FS URL>
example:
python upload.py foo.txt ftp://example.org/uploads/
"""
import sys
import os
from fs import open_fs
_, file_path, fs_url = sys.argv
filename = os.path.basename(file_path)
with open_fs(fs_url) as fs:... | 31 | 524 |
pyfilesystem2 | examples/count_py.py | .py | """
Display how much storage is used in your Python files.
Usage:
python count_py.py <PATH or FS URL>
"""
import sys
from fs import open_fs
from fs.filesize import traditional
fs_url = sys.argv[1]
count = 0
with open_fs(fs_url) as fs:
for _path, info in fs.walk.info(filter=["*.py"], namespaces=["details"]... | 22 | 415 |
pyfilesystem2 | fs/copy.py | .py | """Functions for copying resources *between* filesystem.
"""
from __future__ import print_function, unicode_literals
import typing
import warnings
from .errors import IllegalDestination, ResourceNotFound
from .opener import manage_fs
from .path import abspath, combine, frombase, isbase, normpath
from .tools import ... | 539 | 18,574 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.