Uploaded Test files

This commit is contained in:
Batuhan Berk Başoğlu 2020-11-12 11:05:57 -05:00
parent f584ad9d97
commit 2e81cb7d99
16627 changed files with 2065359 additions and 102444 deletions

View file

@ -0,0 +1,27 @@
"""Tests for IPython.utils.importstring."""
# Copyright (c) IPython Development Team.
# Distributed under the terms of the Modified BSD License.
import nose.tools as nt
from ..importstring import import_item
def test_import_plain():
"Test simple imports"
import os
os2 = import_item('os')
nt.assert_true(os is os2)
def test_import_nested():
"Test nested imports from the stdlib"
from os import path
path2 = import_item('os.path')
nt.assert_true(path is path2)
def test_import_raises():
"Test that failing imports raise the right exception"
nt.assert_raises(ImportError, import_item, 'IPython.foobar')

View file

@ -0,0 +1,108 @@
# encoding: utf-8
"""Tests for genutils.path"""
# Copyright (c) IPython Development Team.
# Distributed under the terms of the Modified BSD License.
import os
import sys
import tempfile
import nose.tools as nt
from ..testing.decorators import skip_if_not_win32, skip_win32
from .. import path
from .. import py3compat
from ..tempdir import TemporaryDirectory
def test_filefind():
f = tempfile.NamedTemporaryFile()
t = path.filefind(f.name, '.')
def test_ensure_dir_exists():
with TemporaryDirectory() as td:
d = os.path.join(td, u'∂ir')
path.ensure_dir_exists(d) # create it
assert os.path.isdir(d)
path.ensure_dir_exists(d) # no-op
f = os.path.join(td, u'ƒile')
open(f, 'w').close() # touch
with nt.assert_raises(IOError):
path.ensure_dir_exists(f)
class TestLinkOrCopy(object):
def setUp(self):
self.tempdir = TemporaryDirectory()
self.src = self.dst("src")
with open(self.src, "w") as f:
f.write("Hello, world!")
def tearDown(self):
self.tempdir.cleanup()
def dst(self, *args):
return os.path.join(self.tempdir.name, *args)
def assert_inode_not_equal(self, a, b):
nt.assert_not_equals(os.stat(a).st_ino, os.stat(b).st_ino,
"%r and %r do reference the same indoes" %(a, b))
def assert_inode_equal(self, a, b):
nt.assert_equals(os.stat(a).st_ino, os.stat(b).st_ino,
"%r and %r do not reference the same indoes" %(a, b))
def assert_content_equal(self, a, b):
with open(a) as a_f:
with open(b) as b_f:
nt.assert_equals(a_f.read(), b_f.read())
@skip_win32
def test_link_successful(self):
dst = self.dst("target")
path.link_or_copy(self.src, dst)
self.assert_inode_equal(self.src, dst)
@skip_win32
def test_link_into_dir(self):
dst = self.dst("some_dir")
os.mkdir(dst)
path.link_or_copy(self.src, dst)
expected_dst = self.dst("some_dir", os.path.basename(self.src))
self.assert_inode_equal(self.src, expected_dst)
@skip_win32
def test_target_exists(self):
dst = self.dst("target")
open(dst, "w").close()
path.link_or_copy(self.src, dst)
self.assert_inode_equal(self.src, dst)
@skip_win32
def test_no_link(self):
real_link = os.link
try:
del os.link
dst = self.dst("target")
path.link_or_copy(self.src, dst)
self.assert_content_equal(self.src, dst)
self.assert_inode_not_equal(self.src, dst)
finally:
os.link = real_link
@skip_if_not_win32
def test_windows(self):
dst = self.dst("target")
path.link_or_copy(self.src, dst)
self.assert_content_equal(self.src, dst)
def test_link_twice(self):
# Linking the same file twice shouldn't leave duplicates around.
# See https://github.com/ipython/ipython/issues/6450
dst = self.dst('target')
path.link_or_copy(self.src, dst)
path.link_or_copy(self.src, dst)
self.assert_inode_equal(self.src, dst)
nt.assert_equal(sorted(os.listdir(self.tempdir.name)), ['src', 'target'])

View file

@ -0,0 +1,22 @@
import os
from ..tempdir import NamedFileInTemporaryDirectory
from ..tempdir import TemporaryWorkingDirectory
def test_named_file_in_temporary_directory():
with NamedFileInTemporaryDirectory('filename') as file:
name = file.name
assert not file.closed
assert os.path.exists(name)
file.write(b'test')
assert file.closed
assert not os.path.exists(name)
def test_temporary_working_directory():
with TemporaryWorkingDirectory() as dir:
assert os.path.exists(dir)
assert os.path.realpath(os.curdir) == os.path.realpath(dir)
assert not os.path.exists(dir)
assert os.path.abspath(os.curdir) != dir

View file

@ -0,0 +1,59 @@
# encoding: utf-8
"""Tests for IPython.utils.text"""
from __future__ import print_function
# Copyright (c) IPython Development Team.
# Distributed under the terms of the Modified BSD License.
import os
import math
import random
import sys
import nose.tools as nt
from .. import text
def test_columnize():
"""Basic columnize tests."""
size = 5
items = [l*size for l in 'abc']
out = text.columnize(items, displaywidth=80)
nt.assert_equal(out, 'aaaaa bbbbb ccccc\n')
out = text.columnize(items, displaywidth=12)
nt.assert_equal(out, 'aaaaa ccccc\nbbbbb\n')
out = text.columnize(items, displaywidth=10)
nt.assert_equal(out, 'aaaaa\nbbbbb\nccccc\n')
def test_columnize_random():
"""Test with random input to hopfully catch edge case """
for nitems in [random.randint(2,70) for i in range(2,20)]:
displaywidth = random.randint(20,200)
rand_len = [random.randint(2,displaywidth) for i in range(nitems)]
items = ['x'*l for l in rand_len]
out = text.columnize(items, displaywidth=displaywidth)
longer_line = max([len(x) for x in out.split('\n')])
longer_element = max(rand_len)
if longer_line > displaywidth:
print("Columnize displayed something lager than displaywidth : %s " % longer_line)
print("longer element : %s " % longer_element)
print("displaywidth : %s " % displaywidth)
print("number of element : %s " % nitems)
print("size of each element :\n %s" % rand_len)
assert False
def test_columnize_medium():
"""Test with inputs than shouldn't be wider tahn 80 """
size = 40
items = [l*size for l in 'abc']
out = text.columnize(items, displaywidth=80)
nt.assert_equal(out, '\n'.join(items+['']))
def test_columnize_long():
"""Test columnize with inputs longer than the display window"""
size = 11
items = [l*size for l in 'abc']
out = text.columnize(items, displaywidth=size-1)
nt.assert_equal(out, '\n'.join(items+['']))