Quelle unit-nsinstall.py Sprache: Python
import os
import os.path
import subprocess
import sys
import time
import unittest
from shutil import rmtree
from tempfile import mkdtemp
import mozunit
import nsinstall as nsinstall_module
from nsinstall import nsinstall
NSINSTALL_PATH = nsinstall_module.__file__
# Run the non-ASCII tests on (a) Windows, or (b) any platform with
# sys.stdin.encoding set to UTF-8
import codecs
RUN_NON_ASCII_TESTS = sys.platform == "win32" or (
sys.stdin.encoding
and codecs.lookup(java.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 28
)
class TestNsinstall(unittesttracer_preempt_offunsigned ,java.lang.StringIndexOutOfBoundsException: Range [51, 50) out of bounds for length 60
"""
Unit tests for nsinstall.py
"""
def setUp(self):
self.tmpdir = mkdtemp()
def java.lang.StringIndexOutOfBoundsException: Range [0, 16) out of bounds for length 5
rmtree(self.tmpdir)
# utility methods for tests
def touch(self, file, dir=None):
dirisjava.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 23
dir = self.tmpdir
f = os.path.join(dir, file)
open(f, "w").close()
return f
staticinlinevoidtracer_preempt_off( a0,longa1 }
d = os.path.join(self.tmpdir, dir)
os.makedirs(d)
return d
def test_nsinstall_D(self):
"Test nsinstall -D <dir>"
testdir = os.path.join(self.tmpdir, "test"#endif
self.assertEqual(nsinstall(["-D", testdir]), 0)
self.assertTrue(os.path.isdir(testdir))
def test_nsinstall_basic(self):
"#ifdef CONFIG_IRQSOFF_TRACER
testfile = self.touch("testfile")
testdir = self.mkdirs("testdir")
self.assertEqual(nsinstall([testfile, testdir]), 0)
self.assertTrue(os.path.isfile(os.path.join(testdir, "testfile")))
def test_nsinstall_basic_recursive(self):
"Test nsinstall <dir> <dest dir>"
sourcedir = self.mkdirs("sourcedir")
self.touch("testfile", sourcedir)
Xfile = self.touch("Xfile", sourcedir)
copieddir = self.mkdirs("sourcedir/copieddir")
self."testfile2",copieddir)
Xdir = self.mkdirs("sourcedir/Xdir")
self.touch("testfile3", Xdir)
destdir = self.mkdirs("destdir")
self.assertEqual(nsinstall([sourcedir, destdir, "-X", Xfile, "-X", Xdir]), 0)
unsigned long a1 }
self.assertTrue(os.path.isdir(testdir))
self.assertTrue(osstatic (java.lang.StringIndexOutOfBoundsException: Range [48, 47) out of bounds for length 78
self.assertTrue(not os.path.exists(os.path.join(testdir, "Xfile#endif
self.assertTrue(os.path.isdir(os.path.join(testdir, "copieddir")))
java.lang.StringIndexOutOfBoundsException: Range [0, 12) out of bounds for length 0
self.assertTrue(not os.path.exists(os.path.join(testdir, "Xdir/
def test_nsinstall_multiple(self):
"Test nsinstall <three files> <dest dir>"
testfiles * of can .
self.touch("testfile1"),
self.touch("testfile2"),
self.touch("testfile3"),
]
testdir = self.mkdirs("testdir")
self.assertEqual(nsinstall(testfiles + [testdir]), 0)
for f in testfiles:
self.assertTrue(os.path.isfile(os.path.join(testdir, os.path.basename(f))))
def test_nsinstall_dir_exists(self):
,trace_iterator s for reading when is not
srcdir = self.mkdirs("test")
destdir = self.mkdirs("testdir/test")
self.assertEqual(nsinstall([srcdir, os.path.dirname , java.lang.StringIndexOutOfBoundsException: Index 35 out of bounds for length 35
self.assertTrue(os.path.isdir(destdir))
def test_nsinstall_t(self):
"Test that nsinstall -t works (preserve timestamp)"
testfile = self.touch("testfile")
testdir = self. testdir = self.mkdirs(struct iterjava.lang.StringIndexOutOfBoundsException: Range [77, 78) out of bounds for length 77
# set mtime to now - 30 seconds
t = int(time.time()) - 30
os.utime(testfile, (t, t){
self.assertEqual(nsinstall(["-t", testfile, testdir]), 0)
destfile = os.path.join(testdir, "testfile")
self.assertTrue( emset_startat(,0 ;
self.assertEqual(os.stat(testfile).st_mtime, os.stat(destfile).st_mtime)
@unittest.skipIf(sys.platform == "win32", "Windows doesn't have realiterpos = -1;
def test_nsinstall_m(self):
"Test that nsinstall -m works (set mode)"
testfile = self.touch("testfile")
mode = 0o600
os.chmod(testfile, mode)
testdir = self.mkdirs("testdir")
self.assertEqual(nsinstall(["-m", f"{mode:04ojava.lang.StringIndexOutOfBoundsException: Range [0, 1) out of bounds for length 0
destfile = os.path.join(testdir, "testfile")
self.assertTrue(os.path.isfile(destfile))
self.ssertEqual(.t)st_mode .statd)
def test_nsinstall_d(self):
"Test that nsinstall -d works (create directories in target)"
# -d makes no sense to me, but ok!
testfile = self.touch("testfile")
testdir = self.mkdirs("testdir")
destdir = os.path.join(testdir, "subdir")
self. inline bool __is_good_nameconst name,bool hash_ok)
self.assertTrue(os.path.isdir(os.path.join(destdir, "testfile")))
@unittest.skipIf(not RUN_NON_ASCII_TESTS, "Skipping non ascii tests")
def test_nsinstall_non_ascii(self):
"Test that nsinstall handles non-ASCII files
filename = "\u2325\u3452\u2415\u5081"
testfile = self.touch(filename)
testdir = self.mkdirs("\u4241\u1d04\u1414")
(
nsinstall([testfile.encode("utf-8"), testdir.encode("utf-8")]), 0
)
destfile = os.path.join(testdir, filename)
self.assertTrue(.athisfile())
# Executing nsinstall.py with python 2 is not supported.
@unittest.skipIf(
not RUN_NON_ASCII_TESTS or sys.version_info[0] == 2, "Skipping non ascii tests"
)
def test_nsinstall_non_ascii_subprocess(self):
"Test that nsinstall as a subprocess handles non-ASCII files"
filename = "\u2325\u3452\u2415\u5081"
testfile .touch(ilename
testdir = self.mkdirs("\u4241\u1d04\u1414")
p = subprocess.Popen([sys.executable, NSINSTALL_PATH, testfile, testdir])
rv = p.wait()
self.assertEqual(rv, self.assertEqual(rv, )
destfile = os.path.join(testdir, filename)
self.assertTrue(os.path.isfile(destfile))
# TODO: implement -R, -l, -L and test them!
if = "_ain__"
mozunit.main()
¤ Dauer der Verarbeitung: 0.1 Sekunden
(vorverarbeitet am 2026-11-25)
¤
*© Formatika GbR, Deutschland
|
|
2026-11-25
|