| 1 |
# vim: set ft=python ts=4 sw=4 expandtab: |
| 2 |
# ruff: file-ignore[builtin-variable-shadowing, uncapitalized-environment-variables] |
| 3 |
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # |
| 4 |
# |
| 5 |
# C E D A R |
| 6 |
# S O L U T I O N S "Software done right." |
| 7 |
# S O F T W A R E |
| 8 |
# |
| 9 |
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # |
| 10 |
# |
| 11 |
# Copyright (c) 2004-2008,2010,2015 Kenneth J. Pronovici. |
| 12 |
# All rights reserved. |
| 13 |
# |
| 14 |
# This program is free software; you can redistribute it and/or |
| 15 |
# modify it under the terms of the GNU General Public License, |
| 16 |
# Version 2, as published by the Free Software Foundation. |
| 17 |
# |
| 18 |
# This program is distributed in the hope that it will be useful, |
| 19 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 21 |
# |
| 22 |
# Copies of the GNU General Public License are available from |
| 23 |
# the Free Software Foundation website, http://www.gnu.org/. |
| 24 |
# |
| 25 |
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # |
| 26 |
# |
| 27 |
# Author : Kenneth J. Pronovici <[email protected]> |
| 28 |
# Language : Python 3 |
| 29 |
# Project : Cedar Backup, release 3 |
| 30 |
# Purpose : Tests utility functionality. |
| 31 |
# |
| 32 |
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # |
| 33 |
|
| 34 |
######################################################################## |
| 35 |
# Module documentation |
| 36 |
######################################################################## |
| 37 |
|
| 38 |
""" |
| 39 |
Unit tests for CedarBackup3/util.py. |
| 40 |
|
| 41 |
Code Coverage |
| 42 |
============= |
| 43 |
|
| 44 |
This module contains individual tests for the public functions and classes |
| 45 |
implemented in util.py. |
| 46 |
|
| 47 |
Naming Conventions |
| 48 |
================== |
| 49 |
|
| 50 |
I prefer to avoid large unit tests which validate more than one piece of |
| 51 |
functionality, and I prefer to avoid using overly descriptive (read: long) |
| 52 |
test names, as well. Instead, I use lots of very small tests that each |
| 53 |
validate one specific thing. These small tests are then named with an index |
| 54 |
number, yielding something like ``testAddDir_001`` or ``testValidate_010``. |
| 55 |
Each method has a docstring describing what it's supposed to accomplish. I |
| 56 |
feel that this makes it easier to judge how important a given failure is, |
| 57 |
and also makes it somewhat easier to diagnose and fix individual problems. |
| 58 |
|
| 59 |
Full vs. Reduced Tests |
| 60 |
====================== |
| 61 |
|
| 62 |
All of the tests in this module are considered safe to be run in an average |
| 63 |
build environment. There is a no need to use a UTILTESTS_FULL environment |
| 64 |
variable to provide a "reduced feature set" test suite as for some of the |
| 65 |
other test modules. |
| 66 |
|
| 67 |
@author Kenneth J. Pronovici <[email protected]> |
| 68 |
""" |
| 69 |
|
| 70 |
|
| 71 |
######################################################################## |
| 72 |
# Import modules and do runtime validations |
| 73 |
######################################################################## |
| 74 |
|
| 75 |
import logging |
| 76 |
import os |
| 77 |
import sys |
| 78 |
import tempfile |
| 79 |
import time |
| 80 |
import unittest |
| 81 |
from os.path import isdir |
| 82 |
|
| 83 |
from CedarBackup3.testutil import ( |
| 84 |
buildPath, |
| 85 |
captureOutput, |
| 86 |
configureLogging, |
| 87 |
extractTar, |
| 88 |
findResources, |
| 89 |
platformSupportsLinks, |
| 90 |
platformWindows, |
| 91 |
removedir, |
| 92 |
) |
| 93 |
from CedarBackup3.util import ( |
| 94 |
UNIT_BYTES, |
| 95 |
UNIT_GBYTES, |
| 96 |
UNIT_KBYTES, |
| 97 |
UNIT_MBYTES, |
| 98 |
UNIT_SECTORS, |
| 99 |
AbsolutePathList, |
| 100 |
Diagnostics, |
| 101 |
DirectedGraph, |
| 102 |
ObjectTypeList, |
| 103 |
PathResolverSingleton, |
| 104 |
RegexList, |
| 105 |
RegexMatchList, |
| 106 |
RestrictedContentList, |
| 107 |
UnorderedList, |
| 108 |
buildNormalizedPath, |
| 109 |
convertSize, |
| 110 |
dereferenceLink, |
| 111 |
deriveDayOfWeek, |
| 112 |
displayBytes, |
| 113 |
encodePath, |
| 114 |
executeCommand, |
| 115 |
getFunctionReference, |
| 116 |
isStartOfWeek, |
| 117 |
nullDevice, |
| 118 |
parseCommaSeparatedString, |
| 119 |
pathJoin, |
| 120 |
resolveCommand, |
| 121 |
sortDict, |
| 122 |
splitCommandLine, |
| 123 |
) |
| 124 |
|
| 125 |
####################################################################### |
| 126 |
# Module-wide configuration and constants |
| 127 |
####################################################################### |
| 128 |
|
| 129 |
DATA_DIRS = ["./data", "./tests/data"] |
| 130 |
RESOURCES = [ |
| 131 |
"lotsoflines.py", |
| 132 |
"tree10.tar.gz", |
| 133 |
] |
| 134 |
|
| 135 |
# This is a command that is always valid on the platform, something other than the Python interpreter |
| 136 |
# The command must return a success status (zero) for the tests to pass |
| 137 |
if platformWindows(): |
| 138 |
VALID_COMMAND = [pathJoin(os.environ["SystemRoot"], "system32", "WindowsPowerShell", "v1.0", "powershell.exe")] |
| 139 |
VALID_ARGS = ["Write-Output hello"] |
| 140 |
VALID_OUTPUT = "hello\r\n" |
| 141 |
else: |
| 142 |
VALID_COMMAND = ["echo"] |
| 143 |
VALID_ARGS = ["hello"] |
| 144 |
VALID_OUTPUT = "hello\n" |
| 145 |
|
| 146 |
|
| 147 |
####################################################################### |
| 148 |
# Test Case Classes |
| 149 |
####################################################################### |
| 150 |
|
| 151 |
########################## |
| 152 |
# TestUnorderedList class |
| 153 |
########################## |
| 154 |
|
| 155 |
|
| 156 |
class TestUnorderedList(unittest.TestCase): |
| 157 |
"""Tests for the UnorderedList class.""" |
| 158 |
|
| 159 |
################ |
| 160 |
# Setup methods |
| 161 |
################ |
| 162 |
|
| 163 |
@classmethod |
| 164 |
def setUpClass(cls): |
| 165 |
configureLogging() |
| 166 |
|
| 167 |
def setUp(self): |
| 168 |
pass |
| 169 |
|
| 170 |
def tearDown(self): |
| 171 |
pass |
| 172 |
|
| 173 |
################################## |
| 174 |
# Test unordered list comparisons |
| 175 |
################################## |
| 176 |
|
| 177 |
def testComparison_001(self): |
| 178 |
""" |
| 179 |
Test two empty lists. |
| 180 |
""" |
| 181 |
list1 = UnorderedList() |
| 182 |
list2 = UnorderedList() |
| 183 |
self.assertEqual(list1, list2) |
| 184 |
self.assertEqual(list2, list1) |
| 185 |
|
| 186 |
def testComparison_002(self): |
| 187 |
""" |
| 188 |
Test empty vs. non-empty list. |
| 189 |
""" |
| 190 |
list1 = UnorderedList() |
| 191 |
list2 = UnorderedList() |
| 192 |
list1.append(1) |
| 193 |
list1.append(2) |
| 194 |
list1.append(3) |
| 195 |
list1.append(4) |
| 196 |
self.assertEqual([1, 2, 3, 4], list1) |
| 197 |
self.assertEqual([2, 3, 4, 1], list1) |
| 198 |
self.assertEqual([3, 4, 1, 2], list1) |
| 199 |
self.assertEqual([4, 1, 2, 3], list1) |
| 200 |
self.assertEqual(list1, [4, 3, 2, 1]) |
| 201 |
self.assertEqual(list1, [3, 2, 1, 4]) |
| 202 |
self.assertEqual(list1, [2, 1, 4, 3]) |
| 203 |
self.assertEqual(list1, [1, 4, 3, 2]) |
| 204 |
self.assertNotEqual(list1, list2) |
| 205 |
self.assertNotEqual(list2, list1) |
| 206 |
|
| 207 |
def testComparison_003(self): |
| 208 |
""" |
| 209 |
Test two non-empty lists, completely different contents. |
| 210 |
""" |
| 211 |
list1 = UnorderedList() |
| 212 |
list2 = UnorderedList() |
| 213 |
list1.append(1) |
| 214 |
list1.append(2) |
| 215 |
list1.append(3) |
| 216 |
list1.append(4) |
| 217 |
list2.append("a") |
| 218 |
list2.append("b") |
| 219 |
list2.append("c") |
| 220 |
list2.append("d") |
| 221 |
self.assertEqual([1, 2, 3, 4], list1) |
| 222 |
self.assertEqual([2, 3, 4, 1], list1) |
| 223 |
self.assertEqual([3, 4, 1, 2], list1) |
| 224 |
self.assertEqual([4, 1, 2, 3], list1) |
| 225 |
self.assertEqual(list1, [4, 3, 2, 1]) |
| 226 |
self.assertEqual(list1, [3, 2, 1, 4]) |
| 227 |
self.assertEqual(list1, [2, 1, 4, 3]) |
| 228 |
self.assertEqual(list1, [1, 4, 3, 2]) |
| 229 |
self.assertEqual(["a", "b", "c", "d"], list2) |
| 230 |
self.assertEqual(["b", "c", "d", "a"], list2) |
| 231 |
self.assertEqual(["c", "d", "a", "b"], list2) |
| 232 |
self.assertEqual(["d", "a", "b", "c"], list2) |
| 233 |
self.assertEqual(list2, ["d", "c", "b", "a"]) |
| 234 |
self.assertEqual(list2, ["c", "b", "a", "d"]) |
| 235 |
self.assertEqual(list2, ["b", "a", "d", "c"]) |
| 236 |
self.assertEqual(list2, ["a", "d", "c", "b"]) |
| 237 |
self.assertNotEqual(list1, list2) |
| 238 |
self.assertNotEqual(list2, list1) |
| 239 |
|
| 240 |
def testComparison_004(self): |
| 241 |
""" |
| 242 |
Test two non-empty lists, different but overlapping contents. |
| 243 |
""" |
| 244 |
list1 = UnorderedList() |
| 245 |
list2 = UnorderedList() |
| 246 |
list1.append(1) |
| 247 |
list1.append(2) |
| 248 |
list1.append(3) |
| 249 |
list1.append(4) |
| 250 |
list2.append(3) |
| 251 |
list2.append(4) |
| 252 |
list2.append("a") |
| 253 |
list2.append("b") |
| 254 |
self.assertEqual([1, 2, 3, 4], list1) |
| 255 |
self.assertEqual([2, 3, 4, 1], list1) |
| 256 |
self.assertEqual([3, 4, 1, 2], list1) |
| 257 |
self.assertEqual([4, 1, 2, 3], list1) |
| 258 |
self.assertEqual(list1, [4, 3, 2, 1]) |
| 259 |
self.assertEqual(list1, [3, 2, 1, 4]) |
| 260 |
self.assertEqual(list1, [2, 1, 4, 3]) |
| 261 |
self.assertEqual(list1, [1, 4, 3, 2]) |
| 262 |
self.assertEqual([3, 4, "a", "b"], list2) |
| 263 |
self.assertEqual([4, "a", "b", 3], list2) |
| 264 |
self.assertEqual(["a", "b", 3, 4], list2) |
| 265 |
self.assertEqual(["b", 3, 4, "a"], list2) |
| 266 |
self.assertEqual(list2, ["b", "a", 4, 3]) |
| 267 |
self.assertEqual(list2, ["a", 4, 3, "b"]) |
| 268 |
self.assertEqual(list2, [4, 3, "b", "a"]) |
| 269 |
self.assertEqual(list2, [3, "b", "a", 4]) |
| 270 |
self.assertNotEqual(list1, list2) |
| 271 |
self.assertNotEqual(list2, list1) |
| 272 |
|
| 273 |
def testComparison_005(self): |
| 274 |
""" |
| 275 |
Test two non-empty lists, exactly the same contents, same order. |
| 276 |
""" |
| 277 |
list1 = UnorderedList() |
| 278 |
list2 = UnorderedList() |
| 279 |
list1.append(1) |
| 280 |
list1.append(2) |
| 281 |
list1.append(3) |
| 282 |
list1.append(4) |
| 283 |
list2.append(1) |
| 284 |
list2.append(2) |
| 285 |
list2.append(3) |
| 286 |
list2.append(4) |
| 287 |
self.assertEqual([1, 2, 3, 4], list1) |
| 288 |
self.assertEqual([2, 3, 4, 1], list1) |
| 289 |
self.assertEqual([3, 4, 1, 2], list1) |
| 290 |
self.assertEqual([4, 1, 2, 3], list1) |
| 291 |
self.assertEqual(list1, [4, 3, 2, 1]) |
| 292 |
self.assertEqual(list1, [3, 2, 1, 4]) |
| 293 |
self.assertEqual(list1, [2, 1, 4, 3]) |
| 294 |
self.assertEqual(list1, [1, 4, 3, 2]) |
| 295 |
self.assertEqual([1, 2, 3, 4], list2) |
| 296 |
self.assertEqual([2, 3, 4, 1], list2) |
| 297 |
self.assertEqual([3, 4, 1, 2], list2) |
| 298 |
self.assertEqual([4, 1, 2, 3], list2) |
| 299 |
self.assertEqual(list2, [4, 3, 2, 1]) |
| 300 |
self.assertEqual(list2, [3, 2, 1, 4]) |
| 301 |
self.assertEqual(list2, [2, 1, 4, 3]) |
| 302 |
self.assertEqual(list2, [1, 4, 3, 2]) |
| 303 |
self.assertEqual(list1, list2) |
| 304 |
self.assertEqual(list2, list1) |
| 305 |
|
| 306 |
def testComparison_006(self): |
| 307 |
""" |
| 308 |
Test two non-empty lists, exactly the same contents, different order. |
| 309 |
""" |
| 310 |
list1 = UnorderedList() |
| 311 |
list2 = UnorderedList() |
| 312 |
list1.append(1) |
| 313 |
list1.append(2) |
| 314 |
list1.append(3) |
| 315 |
list1.append(4) |
| 316 |
list2.append(3) |
| 317 |
list2.append(1) |
| 318 |
list2.append(2) |
| 319 |
list2.append(4) |
| 320 |
self.assertEqual([1, 2, 3, 4], list1) |
| 321 |
self.assertEqual([2, 3, 4, 1], list1) |
| 322 |
self.assertEqual([3, 4, 1, 2], list1) |
| 323 |
self.assertEqual([4, 1, 2, 3], list1) |
| 324 |
self.assertEqual(list1, [4, 3, 2, 1]) |
| 325 |
self.assertEqual(list1, [3, 2, 1, 4]) |
| 326 |
self.assertEqual(list1, [2, 1, 4, 3]) |
| 327 |
self.assertEqual(list1, [1, 4, 3, 2]) |
| 328 |
self.assertEqual([1, 2, 3, 4], list2) |
| 329 |
self.assertEqual([2, 3, 4, 1], list2) |
| 330 |
self.assertEqual([3, 4, 1, 2], list2) |
| 331 |
self.assertEqual([4, 1, 2, 3], list2) |
| 332 |
self.assertEqual(list2, [4, 3, 2, 1]) |
| 333 |
self.assertEqual(list2, [3, 2, 1, 4]) |
| 334 |
self.assertEqual(list2, [2, 1, 4, 3]) |
| 335 |
self.assertEqual(list2, [1, 4, 3, 2]) |
| 336 |
self.assertEqual(list1, list2) |
| 337 |
self.assertEqual(list2, list1) |
| 338 |
|
| 339 |
def testComparison_007(self): |
| 340 |
""" |
| 341 |
Test two non-empty lists, exactly the same contents, some duplicates, |
| 342 |
same order. |
| 343 |
""" |
| 344 |
list1 = UnorderedList() |
| 345 |
list2 = UnorderedList() |
| 346 |
list1.append(1) |
| 347 |
list1.append(2) |
| 348 |
list1.append(2) |
| 349 |
list1.append(3) |
| 350 |
list1.append(4) |
| 351 |
list1.append(4) |
| 352 |
list2.append(1) |
| 353 |
list2.append(2) |
| 354 |
list2.append(2) |
| 355 |
list2.append(3) |
| 356 |
list2.append(4) |
| 357 |
list2.append(4) |
| 358 |
self.assertEqual([1, 2, 2, 3, 4, 4], list1) |
| 359 |
self.assertEqual([2, 2, 3, 4, 1, 4], list1) |
| 360 |
self.assertEqual([2, 3, 4, 1, 4, 2], list1) |
| 361 |
self.assertEqual([2, 4, 1, 4, 2, 3], list1) |
| 362 |
self.assertEqual(list1, [1, 2, 2, 3, 4, 4]) |
| 363 |
self.assertEqual(list1, [2, 2, 3, 4, 1, 4]) |
| 364 |
self.assertEqual(list1, [2, 3, 4, 1, 4, 2]) |
| 365 |
self.assertEqual(list1, [2, 4, 1, 4, 2, 3]) |
| 366 |
self.assertEqual([1, 2, 2, 3, 4, 4], list2) |
| 367 |
self.assertEqual([2, 2, 3, 4, 1, 4], list2) |
| 368 |
self.assertEqual([2, 3, 4, 1, 4, 2], list2) |
| 369 |
self.assertEqual([2, 4, 1, 4, 2, 3], list2) |
| 370 |
self.assertEqual(list2, [1, 2, 2, 3, 4, 4]) |
| 371 |
self.assertEqual(list2, [2, 2, 3, 4, 1, 4]) |
| 372 |
self.assertEqual(list2, [2, 3, 4, 1, 4, 2]) |
| 373 |
self.assertEqual(list2, [2, 4, 1, 4, 2, 3]) |
| 374 |
self.assertEqual(list1, list2) |
| 375 |
self.assertEqual(list2, list1) |
| 376 |
|
| 377 |
def testComparison_008(self): |
| 378 |
""" |
| 379 |
Test two non-empty lists, exactly the same contents, some duplicates, |
| 380 |
different order. |
| 381 |
""" |
| 382 |
list1 = UnorderedList() |
| 383 |
list2 = UnorderedList() |
| 384 |
list1.append(1) |
| 385 |
list1.append(2) |
| 386 |
list1.append(2) |
| 387 |
list1.append(3) |
| 388 |
list1.append(4) |
| 389 |
list1.append(4) |
| 390 |
list2.append(3) |
| 391 |
list2.append(1) |
| 392 |
list2.append(2) |
| 393 |
list2.append(2) |
| 394 |
list2.append(4) |
| 395 |
list2.append(4) |
| 396 |
self.assertEqual([1, 2, 2, 3, 4, 4], list1) |
| 397 |
self.assertEqual([2, 2, 3, 4, 1, 4], list1) |
| 398 |
self.assertEqual([2, 3, 4, 1, 4, 2], list1) |
| 399 |
self.assertEqual([2, 4, 1, 4, 2, 3], list1) |
| 400 |
self.assertEqual(list1, [1, 2, 2, 3, 4, 4]) |
| 401 |
self.assertEqual(list1, [2, 2, 3, 4, 1, 4]) |
| 402 |
self.assertEqual(list1, [2, 3, 4, 1, 4, 2]) |
| 403 |
self.assertEqual(list1, [2, 4, 1, 4, 2, 3]) |
| 404 |
self.assertEqual([1, 2, 2, 3, 4, 4], list2) |
| 405 |
self.assertEqual([2, 2, 3, 4, 1, 4], list2) |
| 406 |
self.assertEqual([2, 3, 4, 1, 4, 2], list2) |
| 407 |
self.assertEqual([2, 4, 1, 4, 2, 3], list2) |
| 408 |
self.assertEqual(list2, [1, 2, 2, 3, 4, 4]) |
| 409 |
self.assertEqual(list2, [2, 2, 3, 4, 1, 4]) |
| 410 |
self.assertEqual(list2, [2, 3, 4, 1, 4, 2]) |
| 411 |
self.assertEqual(list2, [2, 4, 1, 4, 2, 3]) |
| 412 |
self.assertEqual(list1, list2) |
| 413 |
self.assertEqual(list2, list1) |
| 414 |
|
| 415 |
|
| 416 |
############################# |
| 417 |
# TestAbsolutePathList class |
| 418 |
############################# |
| 419 |
|
| 420 |
|
| 421 |
class TestAbsolutePathList(unittest.TestCase): |
| 422 |
"""Tests for the AbsolutePathList class.""" |
| 423 |
|
| 424 |
################ |
| 425 |
# Setup methods |
| 426 |
################ |
| 427 |
|
| 428 |
@classmethod |
| 429 |
def setUpClass(cls): |
| 430 |
configureLogging() |
| 431 |
|
| 432 |
def setUp(self): |
| 433 |
pass |
| 434 |
|
| 435 |
def tearDown(self): |
| 436 |
pass |
| 437 |
|
| 438 |
####################### |
| 439 |
# Test list operations |
| 440 |
####################### |
| 441 |
|
| 442 |
def testListOperations_001(self): |
| 443 |
""" |
| 444 |
Test append() for a valid absolute path. |
| 445 |
""" |
| 446 |
list1 = AbsolutePathList() |
| 447 |
list1.append("/path/to/something/absolute") |
| 448 |
self.assertEqual(list1, ["/path/to/something/absolute"]) |
| 449 |
self.assertEqual(list1[0], "/path/to/something/absolute") |
| 450 |
list1.append("/path/to/something/else") |
| 451 |
self.assertEqual(list1, ["/path/to/something/absolute", "/path/to/something/else"]) |
| 452 |
self.assertEqual(list1[0], "/path/to/something/absolute") |
| 453 |
self.assertEqual(list1[1], "/path/to/something/else") |
| 454 |
|
| 455 |
def testListOperations_002(self): |
| 456 |
""" |
| 457 |
Test append() for an invalid, non-absolute path. |
| 458 |
""" |
| 459 |
list1 = AbsolutePathList() |
| 460 |
self.assertEqual(list1, []) |
| 461 |
self.assertRaises(ValueError, list1.append, "path/to/something/relative") |
| 462 |
self.assertEqual(list1, []) |
| 463 |
|
| 464 |
def testListOperations_003(self): |
| 465 |
""" |
| 466 |
Test insert() for a valid absolute path. |
| 467 |
""" |
| 468 |
list1 = AbsolutePathList() |
| 469 |
list1.insert(0, "/path/to/something/absolute") |
| 470 |
self.assertEqual(list1, ["/path/to/something/absolute"]) |
| 471 |
self.assertEqual(list1[0], "/path/to/something/absolute") |
| 472 |
list1.insert(0, "/path/to/something/else") |
| 473 |
self.assertEqual(list1, ["/path/to/something/else", "/path/to/something/absolute"]) |
| 474 |
self.assertEqual(list1[0], "/path/to/something/else") |
| 475 |
self.assertEqual(list1[1], "/path/to/something/absolute") |
| 476 |
|
| 477 |
def testListOperations_004(self): |
| 478 |
""" |
| 479 |
Test insert() for an invalid, non-absolute path. |
| 480 |
""" |
| 481 |
list1 = AbsolutePathList() |
| 482 |
self.assertRaises(ValueError, list1.insert, 0, "path/to/something/relative") |
| 483 |
|
| 484 |
def testListOperations_005(self): |
| 485 |
""" |
| 486 |
Test extend() for a valid absolute path. |
| 487 |
""" |
| 488 |
list1 = AbsolutePathList() |
| 489 |
list1.extend(["/path/to/something/absolute"]) |
| 490 |
self.assertEqual(list1, ["/path/to/something/absolute"]) |
| 491 |
self.assertEqual(list1[0], "/path/to/something/absolute") |
| 492 |
list1.extend(["/path/to/something/else"]) |
| 493 |
self.assertEqual(list1, ["/path/to/something/absolute", "/path/to/something/else"]) |
| 494 |
self.assertEqual(list1[0], "/path/to/something/absolute") |
| 495 |
self.assertEqual(list1[1], "/path/to/something/else") |
| 496 |
|
| 497 |
def testListOperations_006(self): |
| 498 |
""" |
| 499 |
Test extend() for an invalid, non-absolute path. |
| 500 |
""" |
| 501 |
list1 = AbsolutePathList() |
| 502 |
self.assertEqual(list1, []) |
| 503 |
self.assertRaises(ValueError, list1.extend, ["path/to/something/relative"]) |
| 504 |
self.assertEqual(list1, []) |
| 505 |
|
| 506 |
|
| 507 |
########################### |
| 508 |
# TestObjectTypeList class |
| 509 |
########################### |
| 510 |
|
| 511 |
|
| 512 |
class TestObjectTypeList(unittest.TestCase): |
| 513 |
"""Tests for the ObjectTypeList class.""" |
| 514 |
|
| 515 |
################ |
| 516 |
# Setup methods |
| 517 |
################ |
| 518 |
|
| 519 |
@classmethod |
| 520 |
def setUpClass(cls): |
| 521 |
configureLogging() |
| 522 |
|
| 523 |
def setUp(self): |
| 524 |
pass |
| 525 |
|
| 526 |
def tearDown(self): |
| 527 |
pass |
| 528 |
|
| 529 |
####################### |
| 530 |
# Test list operations |
| 531 |
####################### |
| 532 |
|
| 533 |
def testListOperations_001(self): |
| 534 |
""" |
| 535 |
Test append() for a valid object type. |
| 536 |
""" |
| 537 |
list1 = ObjectTypeList(str, "str") |
| 538 |
list1.append("string") |
| 539 |
self.assertEqual(list1, ["string"]) |
| 540 |
self.assertEqual(list1[0], "string") |
| 541 |
list1.append("string2") |
| 542 |
self.assertEqual(list1, ["string", "string2"]) |
| 543 |
self.assertEqual(list1[0], "string") |
| 544 |
self.assertEqual(list1[1], "string2") |
| 545 |
|
| 546 |
def testListOperations_002(self): |
| 547 |
""" |
| 548 |
Test append() for an invalid object type. |
| 549 |
""" |
| 550 |
list1 = ObjectTypeList(str, "str") |
| 551 |
self.assertEqual(list1, []) |
| 552 |
self.assertRaises(ValueError, list1.append, 1) |
| 553 |
self.assertEqual(list1, []) |
| 554 |
|
| 555 |
def testListOperations_003(self): |
| 556 |
""" |
| 557 |
Test insert() for a valid object type. |
| 558 |
""" |
| 559 |
list1 = ObjectTypeList(str, "str") |
| 560 |
list1.insert(0, "string") |
| 561 |
self.assertEqual(list1, ["string"]) |
| 562 |
self.assertEqual(list1[0], "string") |
| 563 |
list1.insert(0, "string2") |
| 564 |
self.assertEqual(list1, ["string2", "string"]) |
| 565 |
self.assertEqual(list1[0], "string2") |
| 566 |
self.assertEqual(list1[1], "string") |
| 567 |
|
| 568 |
def testListOperations_004(self): |
| 569 |
""" |
| 570 |
Test insert() for an invalid object type. |
| 571 |
""" |
| 572 |
list1 = ObjectTypeList(str, "str") |
| 573 |
self.assertEqual(list1, []) |
| 574 |
self.assertRaises(ValueError, list1.insert, 0, AbsolutePathList()) |
| 575 |
self.assertEqual(list1, []) |
| 576 |
|
| 577 |
def testListOperations_005(self): |
| 578 |
""" |
| 579 |
Test extend() for a valid object type. |
| 580 |
""" |
| 581 |
list1 = ObjectTypeList(str, "str") |
| 582 |
list1.extend(["string"]) |
| 583 |
self.assertEqual(list1, ["string"]) |
| 584 |
self.assertEqual(list1[0], "string") |
| 585 |
list1.extend(["string2"]) |
| 586 |
self.assertEqual(list1, ["string", "string2"]) |
| 587 |
self.assertEqual(list1[0], "string") |
| 588 |
self.assertEqual(list1[1], "string2") |
| 589 |
|
| 590 |
def testListOperations_006(self): |
| 591 |
""" |
| 592 |
Test extend() for an invalid object type. |
| 593 |
""" |
| 594 |
list1 = ObjectTypeList(str, "str") |
| 595 |
self.assertEqual(list1, []) |
| 596 |
self.assertRaises(ValueError, list1.extend, [12.0]) |
| 597 |
self.assertEqual(list1, []) |
| 598 |
|
| 599 |
|
| 600 |
################################## |
| 601 |
# TestRestrictedContentList class |
| 602 |
################################## |
| 603 |
|
| 604 |
|
| 605 |
class TestRestrictedContentList(unittest.TestCase): |
| 606 |
"""Tests for the RestrictedContentList class.""" |
| 607 |
|
| 608 |
################ |
| 609 |
# Setup methods |
| 610 |
################ |
| 611 |
|
| 612 |
def setUp(self): |
| 613 |
pass |
| 614 |
|
| 615 |
def tearDown(self): |
| 616 |
pass |
| 617 |
|
| 618 |
####################### |
| 619 |
# Test list operations |
| 620 |
####################### |
| 621 |
|
| 622 |
def testListOperations_001(self): |
| 623 |
""" |
| 624 |
Test append() for a valid value. |
| 625 |
""" |
| 626 |
list1 = RestrictedContentList(["a", "b", "c"], "values") |
| 627 |
list1.append("a") |
| 628 |
self.assertEqual(list1, ["a"]) |
| 629 |
self.assertEqual(list1[0], "a") |
| 630 |
list1.append("b") |
| 631 |
self.assertEqual(list1, ["a", "b"]) |
| 632 |
self.assertEqual(list1[0], "a") |
| 633 |
self.assertEqual(list1[1], "b") |
| 634 |
list1.append("c") |
| 635 |
self.assertEqual(list1, ["a", "b", "c"]) |
| 636 |
self.assertEqual(list1[0], "a") |
| 637 |
self.assertEqual(list1[1], "b") |
| 638 |
self.assertEqual(list1[2], "c") |
| 639 |
|
| 640 |
def testListOperations_002(self): |
| 641 |
""" |
| 642 |
Test append() for an invalid value. |
| 643 |
""" |
| 644 |
list1 = RestrictedContentList(["a", "b", "c"], "values") |
| 645 |
self.assertEqual(list1, []) |
| 646 |
self.assertRaises(ValueError, list1.append, "d") |
| 647 |
self.assertEqual(list1, []) |
| 648 |
self.assertRaises(ValueError, list1.append, 1) |
| 649 |
self.assertEqual(list1, []) |
| 650 |
self.assertRaises(ValueError, list1.append, UnorderedList()) |
| 651 |
self.assertEqual(list1, []) |
| 652 |
|
| 653 |
def testListOperations_003(self): |
| 654 |
""" |
| 655 |
Test insert() for a valid value. |
| 656 |
""" |
| 657 |
list1 = RestrictedContentList(["a", "b", "c"], "values") |
| 658 |
list1.insert(0, "a") |
| 659 |
self.assertEqual(list1, ["a"]) |
| 660 |
self.assertEqual(list1[0], "a") |
| 661 |
list1.insert(0, "b") |
| 662 |
self.assertEqual(list1, ["b", "a"]) |
| 663 |
self.assertEqual(list1[0], "b") |
| 664 |
self.assertEqual(list1[1], "a") |
| 665 |
list1.insert(0, "c") |
| 666 |
self.assertEqual(list1, ["c", "b", "a"]) |
| 667 |
self.assertEqual(list1[0], "c") |
| 668 |
self.assertEqual(list1[1], "b") |
| 669 |
self.assertEqual(list1[2], "a") |
| 670 |
|
| 671 |
def testListOperations_004(self): |
| 672 |
""" |
| 673 |
Test insert() for an invalid value. |
| 674 |
""" |
| 675 |
list1 = RestrictedContentList(["a", "b", "c"], "values") |
| 676 |
self.assertEqual(list1, []) |
| 677 |
self.assertRaises(ValueError, list1.insert, 0, "d") |
| 678 |
self.assertEqual(list1, []) |
| 679 |
self.assertRaises(ValueError, list1.insert, 0, 1) |
| 680 |
self.assertEqual(list1, []) |
| 681 |
self.assertRaises(ValueError, list1.insert, 0, UnorderedList()) |
| 682 |
self.assertEqual(list1, []) |
| 683 |
|
| 684 |
def testListOperations_005(self): |
| 685 |
""" |
| 686 |
Test extend() for a valid value. |
| 687 |
""" |
| 688 |
list1 = RestrictedContentList(["a", "b", "c"], "values") |
| 689 |
list1.extend(["a"]) |
| 690 |
self.assertEqual(list1, ["a"]) |
| 691 |
self.assertEqual(list1[0], "a") |
| 692 |
list1.extend(["b"]) |
| 693 |
self.assertEqual(list1, ["a", "b"]) |
| 694 |
self.assertEqual(list1[0], "a") |
| 695 |
self.assertEqual(list1[1], "b") |
| 696 |
list1.extend(["c"]) |
| 697 |
self.assertEqual(list1, ["a", "b", "c"]) |
| 698 |
self.assertEqual(list1[0], "a") |
| 699 |
self.assertEqual(list1[1], "b") |
| 700 |
self.assertEqual(list1[2], "c") |
| 701 |
|
| 702 |
def testListOperations_006(self): |
| 703 |
""" |
| 704 |
Test extend() for an invalid value. |
| 705 |
""" |
| 706 |
list1 = RestrictedContentList(["a", "b", "c"], "values") |
| 707 |
self.assertEqual(list1, []) |
| 708 |
self.assertRaises(ValueError, list1.extend, ["d"]) |
| 709 |
self.assertEqual(list1, []) |
| 710 |
self.assertRaises(ValueError, list1.extend, [1]) |
| 711 |
self.assertEqual(list1, []) |
| 712 |
self.assertRaises(ValueError, list1.extend, [UnorderedList()]) |
| 713 |
self.assertEqual(list1, []) |
| 714 |
|
| 715 |
|
| 716 |
########################### |
| 717 |
# TestRegexMatchList class |
| 718 |
########################### |
| 719 |
|
| 720 |
|
| 721 |
class TestRegexMatchList(unittest.TestCase): |
| 722 |
"""Tests for the RegexMatchList class.""" |
| 723 |
|
| 724 |
################ |
| 725 |
# Setup methods |
| 726 |
################ |
| 727 |
|
| 728 |
def setUp(self): |
| 729 |
pass |
| 730 |
|
| 731 |
def tearDown(self): |
| 732 |
pass |
| 733 |
|
| 734 |
####################### |
| 735 |
# Test list operations |
| 736 |
####################### |
| 737 |
|
| 738 |
def testListOperations_001(self): |
| 739 |
""" |
| 740 |
Test append() for a valid value, emptyAllowed=True. |
| 741 |
""" |
| 742 |
list1 = RegexMatchList(r"^[a-z0-9]*$", emptyAllowed=True) |
| 743 |
list1.append("a") |
| 744 |
self.assertEqual(list1, ["a"]) |
| 745 |
self.assertEqual(list1[0], "a") |
| 746 |
list1.append("1") |
| 747 |
self.assertEqual(list1, ["a", "1"]) |
| 748 |
self.assertEqual(list1[0], "a") |
| 749 |
self.assertEqual(list1[1], "1") |
| 750 |
list1.append("abcd12345") |
| 751 |
self.assertEqual(list1, ["a", "1", "abcd12345"]) |
| 752 |
self.assertEqual(list1[0], "a") |
| 753 |
self.assertEqual(list1[1], "1") |
| 754 |
self.assertEqual(list1[2], "abcd12345") |
| 755 |
list1.append("") |
| 756 |
self.assertEqual(list1, ["a", "1", "abcd12345", ""]) |
| 757 |
self.assertEqual(list1[0], "a") |
| 758 |
self.assertEqual(list1[1], "1") |
| 759 |
self.assertEqual(list1[2], "abcd12345") |
| 760 |
self.assertEqual(list1[3], "") |
| 761 |
|
| 762 |
def testListOperations_002(self): |
| 763 |
""" |
| 764 |
Test append() for an invalid value, emptyAllowed=True. |
| 765 |
""" |
| 766 |
list1 = RegexMatchList(r"^[a-z0-9]*$", emptyAllowed=True) |
| 767 |
self.assertEqual(list1, []) |
| 768 |
self.assertRaises(ValueError, list1.append, "A") |
| 769 |
self.assertEqual(list1, []) |
| 770 |
self.assertRaises(ValueError, list1.append, "ABC") |
| 771 |
self.assertEqual(list1, []) |
| 772 |
self.assertRaises(TypeError, list1.append, 12) |
| 773 |
self.assertEqual(list1, []) |
| 774 |
self.assertRaises(ValueError, list1.append, "KEN_12") |
| 775 |
self.assertEqual(list1, []) |
| 776 |
self.assertRaises(ValueError, list1.append, None) |
| 777 |
self.assertEqual(list1, []) |
| 778 |
|
| 779 |
def testListOperations_003(self): |
| 780 |
""" |
| 781 |
Test insert() for a valid value, emptyAllowed=True. |
| 782 |
""" |
| 783 |
list1 = RegexMatchList(r"^[a-z0-9]*$", emptyAllowed=True) |
| 784 |
list1.insert(0, "a") |
| 785 |
self.assertEqual(list1, ["a"]) |
| 786 |
self.assertEqual(list1[0], "a") |
| 787 |
list1.insert(0, "1") |
| 788 |
self.assertEqual(list1, ["1", "a"]) |
| 789 |
self.assertEqual(list1[0], "1") |
| 790 |
self.assertEqual(list1[1], "a") |
| 791 |
list1.insert(0, "abcd12345") |
| 792 |
self.assertEqual(list1, ["abcd12345", "1", "a"]) |
| 793 |
self.assertEqual(list1[0], "abcd12345") |
| 794 |
self.assertEqual(list1[1], "1") |
| 795 |
self.assertEqual(list1[2], "a") |
| 796 |
list1.insert(0, "") |
| 797 |
self.assertEqual(list1, ["abcd12345", "1", "a", ""]) |
| 798 |
self.assertEqual(list1[0], "") |
| 799 |
self.assertEqual(list1[1], "abcd12345") |
| 800 |
self.assertEqual(list1[2], "1") |
| 801 |
self.assertEqual(list1[3], "a") |
| 802 |
|
| 803 |
def testListOperations_004(self): |
| 804 |
""" |
| 805 |
Test insert() for an invalid value, emptyAllowed=True. |
| 806 |
""" |
| 807 |
list1 = RegexMatchList(r"^[a-z0-9]*$", emptyAllowed=True) |
| 808 |
self.assertEqual(list1, []) |
| 809 |
self.assertRaises(ValueError, list1.insert, 0, "A") |
| 810 |
self.assertEqual(list1, []) |
| 811 |
self.assertRaises(ValueError, list1.insert, 0, "ABC") |
| 812 |
self.assertEqual(list1, []) |
| 813 |
self.assertRaises(TypeError, list1.insert, 0, 12) |
| 814 |
self.assertEqual(list1, []) |
| 815 |
self.assertRaises(ValueError, list1.insert, 0, "KEN_12") |
| 816 |
self.assertEqual(list1, []) |
| 817 |
self.assertRaises(ValueError, list1.insert, 0, None) |
| 818 |
self.assertEqual(list1, []) |
| 819 |
|
| 820 |
def testListOperations_005(self): |
| 821 |
""" |
| 822 |
Test extend() for a valid value, emptyAllowed=True. |
| 823 |
""" |
| 824 |
list1 = RegexMatchList(r"^[a-z0-9]*$", emptyAllowed=True) |
| 825 |
list1.extend(["a"]) |
| 826 |
self.assertEqual(list1, ["a"]) |
| 827 |
self.assertEqual(list1[0], "a") |
| 828 |
list1.extend(["1"]) |
| 829 |
self.assertEqual(list1, ["a", "1"]) |
| 830 |
self.assertEqual(list1[0], "a") |
| 831 |
self.assertEqual(list1[1], "1") |
| 832 |
list1.extend(["abcd12345"]) |
| 833 |
self.assertEqual(list1, ["a", "1", "abcd12345"]) |
| 834 |
self.assertEqual(list1[0], "a") |
| 835 |
self.assertEqual(list1[1], "1") |
| 836 |
self.assertEqual(list1[2], "abcd12345") |
| 837 |
list1.extend([""]) |
| 838 |
self.assertEqual(list1, ["a", "1", "abcd12345", ""]) |
| 839 |
self.assertEqual(list1[0], "a") |
| 840 |
self.assertEqual(list1[1], "1") |
| 841 |
self.assertEqual(list1[2], "abcd12345") |
| 842 |
self.assertEqual(list1[3], "") |
| 843 |
|
| 844 |
def testListOperations_006(self): |
| 845 |
""" |
| 846 |
Test extend() for an invalid value, emptyAllowed=True. |
| 847 |
""" |
| 848 |
list1 = RegexMatchList(r"^[a-z0-9]*$", emptyAllowed=True) |
| 849 |
self.assertEqual(list1, []) |
| 850 |
self.assertRaises(ValueError, list1.extend, ["A"]) |
| 851 |
self.assertEqual(list1, []) |
| 852 |
self.assertRaises(ValueError, list1.extend, ["ABC"]) |
| 853 |
self.assertEqual(list1, []) |
| 854 |
self.assertRaises(TypeError, list1.extend, [12]) |
| 855 |
self.assertEqual(list1, []) |
| 856 |
self.assertRaises(ValueError, list1.extend, ["KEN_12"]) |
| 857 |
self.assertEqual(list1, []) |
| 858 |
self.assertRaises(ValueError, list1.extend, [None]) |
| 859 |
self.assertEqual(list1, []) |
| 860 |
|
| 861 |
def testListOperations_007(self): |
| 862 |
""" |
| 863 |
Test append() for a valid value, emptyAllowed=False. |
| 864 |
""" |
| 865 |
list1 = RegexMatchList(r"^[a-z0-9]*$", emptyAllowed=False) |
| 866 |
list1.append("a") |
| 867 |
self.assertEqual(list1, ["a"]) |
| 868 |
self.assertEqual(list1[0], "a") |
| 869 |
list1.append("1") |
| 870 |
self.assertEqual(list1, ["a", "1"]) |
| 871 |
self.assertEqual(list1[0], "a") |
| 872 |
self.assertEqual(list1[1], "1") |
| 873 |
list1.append("abcd12345") |
| 874 |
self.assertEqual(list1, ["a", "1", "abcd12345"]) |
| 875 |
self.assertEqual(list1[0], "a") |
| 876 |
self.assertEqual(list1[1], "1") |
| 877 |
self.assertEqual(list1[2], "abcd12345") |
| 878 |
|
| 879 |
def testListOperations_008(self): |
| 880 |
""" |
| 881 |
Test append() for an invalid value, emptyAllowed=False. |
| 882 |
""" |
| 883 |
list1 = RegexMatchList(r"^[a-z0-9]*$", emptyAllowed=False) |
| 884 |
self.assertEqual(list1, []) |
| 885 |
self.assertRaises(ValueError, list1.append, "A") |
| 886 |
self.assertEqual(list1, []) |
| 887 |
self.assertRaises(ValueError, list1.append, "ABC") |
| 888 |
self.assertEqual(list1, []) |
| 889 |
self.assertRaises(TypeError, list1.append, 12) |
| 890 |
self.assertEqual(list1, []) |
| 891 |
self.assertRaises(ValueError, list1.append, "KEN_12") |
| 892 |
self.assertEqual(list1, []) |
| 893 |
self.assertRaises(ValueError, list1.append, "") |
| 894 |
self.assertEqual(list1, []) |
| 895 |
self.assertRaises(ValueError, list1.append, None) |
| 896 |
self.assertEqual(list1, []) |
| 897 |
|
| 898 |
def testListOperations_009(self): |
| 899 |
""" |
| 900 |
Test insert() for a valid value, emptyAllowed=False. |
| 901 |
""" |
| 902 |
list1 = RegexMatchList(r"^[a-z0-9]*$", emptyAllowed=False) |
| 903 |
list1.insert(0, "a") |
| 904 |
self.assertEqual(list1, ["a"]) |
| 905 |
self.assertEqual(list1[0], "a") |
| 906 |
list1.insert(0, "1") |
| 907 |
self.assertEqual(list1, ["1", "a"]) |
| 908 |
self.assertEqual(list1[0], "1") |
| 909 |
self.assertEqual(list1[1], "a") |
| 910 |
list1.insert(0, "abcd12345") |
| 911 |
self.assertEqual(list1, ["abcd12345", "1", "a"]) |
| 912 |
self.assertEqual(list1[0], "abcd12345") |
| 913 |
self.assertEqual(list1[1], "1") |
| 914 |
self.assertEqual(list1[2], "a") |
| 915 |
|
| 916 |
def testListOperations_010(self): |
| 917 |
""" |
| 918 |
Test insert() for an invalid value, emptyAllowed=False. |
| 919 |
""" |
| 920 |
list1 = RegexMatchList(r"^[a-z0-9]*$", emptyAllowed=False) |
| 921 |
self.assertEqual(list1, []) |
| 922 |
self.assertRaises(ValueError, list1.insert, 0, "A") |
| 923 |
self.assertEqual(list1, []) |
| 924 |
self.assertRaises(ValueError, list1.insert, 0, "ABC") |
| 925 |
self.assertEqual(list1, []) |
| 926 |
self.assertRaises(TypeError, list1.insert, 0, 12) |
| 927 |
self.assertEqual(list1, []) |
| 928 |
self.assertRaises(ValueError, list1.insert, 0, "KEN_12") |
| 929 |
self.assertEqual(list1, []) |
| 930 |
self.assertRaises(ValueError, list1.insert, 0, "") |
| 931 |
self.assertEqual(list1, []) |
| 932 |
self.assertRaises(ValueError, list1.insert, 0, None) |
| 933 |
self.assertEqual(list1, []) |
| 934 |
|
| 935 |
def testListOperations_011(self): |
| 936 |
""" |
| 937 |
Test extend() for a valid value, emptyAllowed=False. |
| 938 |
""" |
| 939 |
list1 = RegexMatchList(r"^[a-z0-9]*$", emptyAllowed=False) |
| 940 |
list1.extend(["a"]) |
| 941 |
self.assertEqual(list1, ["a"]) |
| 942 |
self.assertEqual(list1[0], "a") |
| 943 |
list1.extend(["1"]) |
| 944 |
self.assertEqual(list1, ["a", "1"]) |
| 945 |
self.assertEqual(list1[0], "a") |
| 946 |
self.assertEqual(list1[1], "1") |
| 947 |
list1.extend(["abcd12345"]) |
| 948 |
self.assertEqual(list1, ["a", "1", "abcd12345"]) |
| 949 |
self.assertEqual(list1[0], "a") |
| 950 |
self.assertEqual(list1[1], "1") |
| 951 |
self.assertEqual(list1[2], "abcd12345") |
| 952 |
|
| 953 |
def testListOperations_012(self): |
| 954 |
""" |
| 955 |
Test extend() for an invalid value, emptyAllowed=False. |
| 956 |
""" |
| 957 |
list1 = RegexMatchList(r"^[a-z0-9]*$", emptyAllowed=False) |
| 958 |
self.assertEqual(list1, []) |
| 959 |
self.assertRaises(ValueError, list1.extend, ["A"]) |
| 960 |
self.assertEqual(list1, []) |
| 961 |
self.assertRaises(ValueError, list1.extend, ["ABC"]) |
| 962 |
self.assertEqual(list1, []) |
| 963 |
self.assertRaises(TypeError, list1.extend, [12]) |
| 964 |
self.assertEqual(list1, []) |
| 965 |
self.assertRaises(ValueError, list1.extend, ["KEN_12"]) |
| 966 |
self.assertEqual(list1, []) |
| 967 |
self.assertRaises(ValueError, list1.extend, [""]) |
| 968 |
self.assertEqual(list1, []) |
| 969 |
self.assertRaises(ValueError, list1.extend, [None]) |
| 970 |
self.assertEqual(list1, []) |
| 971 |
|
| 972 |
|
| 973 |
###################### |
| 974 |
# TestRegexList class |
| 975 |
###################### |
| 976 |
|
| 977 |
|
| 978 |
class TestRegexList(unittest.TestCase): |
| 979 |
"""Tests for the RegexList class.""" |
| 980 |
|
| 981 |
################ |
| 982 |
# Setup methods |
| 983 |
################ |
| 984 |
|
| 985 |
def setUp(self): |
| 986 |
pass |
| 987 |
|
| 988 |
def tearDown(self): |
| 989 |
pass |
| 990 |
|
| 991 |
####################### |
| 992 |
# Test list operations |
| 993 |
####################### |
| 994 |
|
| 995 |
def testListOperations_001(self): |
| 996 |
""" |
| 997 |
Test append() for a valid regular expresson. |
| 998 |
""" |
| 999 |
list1 = RegexList() |
| 1000 |
list1.append(r".*\.jpg") |
| 1001 |
self.assertEqual(list1, [r".*\.jpg"]) |
| 1002 |
self.assertEqual(list1[0], r".*\.jpg") |
| 1003 |
list1.append("[a-zA-Z0-9]*") |
| 1004 |
self.assertEqual(list1, [r".*\.jpg", "[a-zA-Z0-9]*"]) |
| 1005 |
self.assertEqual(list1[0], r".*\.jpg") |
| 1006 |
self.assertEqual(list1[1], "[a-zA-Z0-9]*") |
| 1007 |
|
| 1008 |
def testListOperations_002(self): |
| 1009 |
""" |
| 1010 |
Test append() for an invalid regular expression. |
| 1011 |
""" |
| 1012 |
list1 = RegexList() |
| 1013 |
self.assertEqual(list1, []) |
| 1014 |
self.assertRaises(ValueError, list1.append, "*.jpg") |
| 1015 |
self.assertEqual(list1, []) |
| 1016 |
|
| 1017 |
def testListOperations_003(self): |
| 1018 |
""" |
| 1019 |
Test insert() for a valid regular expression. |
| 1020 |
""" |
| 1021 |
list1 = RegexList() |
| 1022 |
list1.insert(0, r".*\.jpg") |
| 1023 |
self.assertEqual(list1, [r".*\.jpg"]) |
| 1024 |
self.assertEqual(list1[0], r".*\.jpg") |
| 1025 |
list1.insert(0, "[a-zA-Z0-9]*") |
| 1026 |
self.assertEqual(list1, ["[a-zA-Z0-9]*", r".*\.jpg"]) |
| 1027 |
self.assertEqual(list1[0], "[a-zA-Z0-9]*") |
| 1028 |
self.assertEqual(list1[1], r".*\.jpg") |
| 1029 |
|
| 1030 |
def testListOperations_004(self): |
| 1031 |
""" |
| 1032 |
Test insert() for an invalid regular expression. |
| 1033 |
""" |
| 1034 |
list1 = RegexList() |
| 1035 |
self.assertRaises(ValueError, list1.insert, 0, "*.jpg") |
| 1036 |
|
| 1037 |
def testListOperations_005(self): |
| 1038 |
""" |
| 1039 |
Test extend() for a valid regular expression. |
| 1040 |
""" |
| 1041 |
list1 = RegexList() |
| 1042 |
list1.extend([r".*\.jpg"]) |
| 1043 |
self.assertEqual(list1, [r".*\.jpg"]) |
| 1044 |
self.assertEqual(list1[0], r".*\.jpg") |
| 1045 |
list1.extend(["[a-zA-Z0-9]*"]) |
| 1046 |
self.assertEqual(list1, [r".*\.jpg", "[a-zA-Z0-9]*"]) |
| 1047 |
self.assertEqual(list1[0], r".*\.jpg") |
| 1048 |
self.assertEqual(list1[1], "[a-zA-Z0-9]*") |
| 1049 |
|
| 1050 |
def testListOperations_006(self): |
| 1051 |
""" |
| 1052 |
Test extend() for an invalid regular expression. |
| 1053 |
""" |
| 1054 |
list1 = RegexList() |
| 1055 |
self.assertEqual(list1, []) |
| 1056 |
self.assertRaises(ValueError, list1.extend, ["*.jpg"]) |
| 1057 |
self.assertEqual(list1, []) |
| 1058 |
|
| 1059 |
|
| 1060 |
########################## |
| 1061 |
# TestDirectedGraph class |
| 1062 |
########################## |
| 1063 |
|
| 1064 |
|
| 1065 |
class TestDirectedGraph(unittest.TestCase): |
| 1066 |
"""Tests for the DirectedGraph class.""" |
| 1067 |
|
| 1068 |
############################ |
| 1069 |
# Test __repr__ and __str__ |
| 1070 |
############################ |
| 1071 |
|
| 1072 |
def testStringFuncs_001(self): |
| 1073 |
""" |
| 1074 |
Just make sure that the string functions don't have errors (i.e. bad variable names). |
| 1075 |
""" |
| 1076 |
obj = DirectedGraph("test") |
| 1077 |
obj.__repr__() |
| 1078 |
obj.__str__() |
| 1079 |
|
| 1080 |
################################## |
| 1081 |
# Test constructor and attributes |
| 1082 |
################################## |
| 1083 |
|
| 1084 |
def testConstructor_001(self): |
| 1085 |
""" |
| 1086 |
Test constructor with a valid name filled in. |
| 1087 |
""" |
| 1088 |
graph = DirectedGraph("Ken") |
| 1089 |
self.assertEqual("Ken", graph.name) |
| 1090 |
|
| 1091 |
def testConstructor_002(self): |
| 1092 |
""" |
| 1093 |
Test constructor with a ``None`` name filled in. |
| 1094 |
""" |
| 1095 |
self.assertRaises(ValueError, DirectedGraph, None) |
| 1096 |
|
| 1097 |
########################## |
| 1098 |
# Test depth first search |
| 1099 |
########################## |
| 1100 |
|
| 1101 |
def testTopologicalSort_001(self): |
| 1102 |
""" |
| 1103 |
Empty graph. |
| 1104 |
""" |
| 1105 |
graph = DirectedGraph("test") |
| 1106 |
path = graph.topologicalSort() |
| 1107 |
self.assertEqual([], path) |
| 1108 |
|
| 1109 |
def testTopologicalSort_002(self): |
| 1110 |
""" |
| 1111 |
Graph with 1 vertex, no edges. |
| 1112 |
""" |
| 1113 |
graph = DirectedGraph("test") |
| 1114 |
graph.createVertex("1") |
| 1115 |
path = graph.topologicalSort() |
| 1116 |
self.assertEqual(["1"], path) |
| 1117 |
|
| 1118 |
def testTopologicalSort_003(self): |
| 1119 |
""" |
| 1120 |
Graph with 2 vertices, no edges. |
| 1121 |
""" |
| 1122 |
graph = DirectedGraph("test") |
| 1123 |
graph.createVertex("1") |
| 1124 |
graph.createVertex("2") |
| 1125 |
path = graph.topologicalSort() |
| 1126 |
self.assertEqual(["2", "1"], path) |
| 1127 |
|
| 1128 |
def testTopologicalSort_004(self): |
| 1129 |
""" |
| 1130 |
Graph with 3 vertices, no edges. |
| 1131 |
""" |
| 1132 |
graph = DirectedGraph("test") |
| 1133 |
graph.createVertex("1") |
| 1134 |
graph.createVertex("2") |
| 1135 |
graph.createVertex("3") |
| 1136 |
path = graph.topologicalSort() |
| 1137 |
self.assertEqual(["3", "2", "1"], path) |
| 1138 |
|
| 1139 |
def testTopologicalSort_005(self): |
| 1140 |
""" |
| 1141 |
Graph with 4 vertices, no edges. |
| 1142 |
""" |
| 1143 |
graph = DirectedGraph("test") |
| 1144 |
graph.createVertex("3") |
| 1145 |
graph.createVertex("1") |
| 1146 |
graph.createVertex("2") |
| 1147 |
graph.createVertex("4") |
| 1148 |
path = graph.topologicalSort() |
| 1149 |
self.assertEqual(["4", "2", "1", "3"], path) |
| 1150 |
|
| 1151 |
def testTopologicalSort_006(self): |
| 1152 |
""" |
| 1153 |
Graph with 4 vertices, no edges. |
| 1154 |
""" |
| 1155 |
graph = DirectedGraph("test") |
| 1156 |
graph.createVertex("3") |
| 1157 |
graph.createVertex("1") |
| 1158 |
graph.createVertex("2") |
| 1159 |
graph.createVertex("4") |
| 1160 |
graph.createVertex("5") |
| 1161 |
path = graph.topologicalSort() |
| 1162 |
self.assertEqual(["5", "4", "2", "1", "3"], path) |
| 1163 |
|
| 1164 |
def testTopologicalSort_007(self): |
| 1165 |
""" |
| 1166 |
Graph with 3 vertices, in a chain (1->2->3), create order (1,2,3) |
| 1167 |
""" |
| 1168 |
graph = DirectedGraph("test") |
| 1169 |
graph.createVertex("1") |
| 1170 |
graph.createVertex("2") |
| 1171 |
graph.createVertex("3") |
| 1172 |
graph.createEdge("1", "2") |
| 1173 |
graph.createEdge("2", "3") |
| 1174 |
path = graph.topologicalSort() |
| 1175 |
self.assertEqual(["1", "2", "3"], path) |
| 1176 |
|
| 1177 |
def testTopologicalSort_008(self): |
| 1178 |
""" |
| 1179 |
Graph with 3 vertices, in a chain (1->2->3), create order (1,3,2) |
| 1180 |
""" |
| 1181 |
graph = DirectedGraph("test") |
| 1182 |
graph.createVertex("1") |
| 1183 |
graph.createVertex("3") |
| 1184 |
graph.createVertex("2") |
| 1185 |
graph.createEdge("1", "2") |
| 1186 |
graph.createEdge("2", "3") |
| 1187 |
path = graph.topologicalSort() |
| 1188 |
self.assertEqual(["1", "2", "3"], path) |
| 1189 |
|
| 1190 |
def testTopologicalSort_009(self): |
| 1191 |
""" |
| 1192 |
Graph with 3 vertices, in a chain (1->2->3), create order (2,3,1) |
| 1193 |
""" |
| 1194 |
graph = DirectedGraph("test") |
| 1195 |
graph.createVertex("2") |
| 1196 |
graph.createVertex("3") |
| 1197 |
graph.createVertex("1") |
| 1198 |
graph.createEdge("1", "2") |
| 1199 |
graph.createEdge("2", "3") |
| 1200 |
path = graph.topologicalSort() |
| 1201 |
self.assertEqual(["1", "2", "3"], path) |
| 1202 |
|
| 1203 |
def testTopologicalSort_010(self): |
| 1204 |
""" |
| 1205 |
Graph with 3 vertices, in a chain (1->2->3), create order (2,1,3) |
| 1206 |
""" |
| 1207 |
graph = DirectedGraph("test") |
| 1208 |
graph.createVertex("2") |
| 1209 |
graph.createVertex("1") |
| 1210 |
graph.createVertex("3") |
| 1211 |
graph.createEdge("1", "2") |
| 1212 |
graph.createEdge("2", "3") |
| 1213 |
path = graph.topologicalSort() |
| 1214 |
self.assertEqual(["1", "2", "3"], path) |
| 1215 |
|
| 1216 |
def testTopologicalSort_011(self): |
| 1217 |
""" |
| 1218 |
Graph with 3 vertices, in a chain (1->2->3), create order (3,1,2) |
| 1219 |
""" |
| 1220 |
graph = DirectedGraph("test") |
| 1221 |
graph.createVertex("3") |
| 1222 |
graph.createVertex("1") |
| 1223 |
graph.createVertex("2") |
| 1224 |
graph.createEdge("1", "2") |
| 1225 |
graph.createEdge("2", "3") |
| 1226 |
path = graph.topologicalSort() |
| 1227 |
self.assertEqual(["1", "2", "3"], path) |
| 1228 |
|
| 1229 |
def testTopologicalSort_012(self): |
| 1230 |
""" |
| 1231 |
Graph with 3 vertices, in a chain (1->2->3), create order (3,2,1) |
| 1232 |
""" |
| 1233 |
graph = DirectedGraph("test") |
| 1234 |
graph.createVertex("3") |
| 1235 |
graph.createVertex("2") |
| 1236 |
graph.createVertex("1") |
| 1237 |
graph.createEdge("1", "2") |
| 1238 |
graph.createEdge("2", "3") |
| 1239 |
path = graph.topologicalSort() |
| 1240 |
self.assertEqual(["1", "2", "3"], path) |
| 1241 |
|
| 1242 |
def testTopologicalSort_013(self): |
| 1243 |
""" |
| 1244 |
Graph with 3 vertices, in a chain (3->2->1), create order (1,2,3) |
| 1245 |
""" |
| 1246 |
graph = DirectedGraph("test") |
| 1247 |
graph.createVertex("1") |
| 1248 |
graph.createVertex("2") |
| 1249 |
graph.createVertex("3") |
| 1250 |
graph.createEdge("3", "2") |
| 1251 |
graph.createEdge("2", "1") |
| 1252 |
path = graph.topologicalSort() |
| 1253 |
self.assertEqual(["3", "2", "1"], path) |
| 1254 |
|
| 1255 |
def testTopologicalSort_014(self): |
| 1256 |
""" |
| 1257 |
Graph with 3 vertices, in a chain (3->2->1), create order (1,3,2) |
| 1258 |
""" |
| 1259 |
graph = DirectedGraph("test") |
| 1260 |
graph.createVertex("1") |
| 1261 |
graph.createVertex("3") |
| 1262 |
graph.createVertex("2") |
| 1263 |
graph.createEdge("3", "2") |
| 1264 |
graph.createEdge("2", "1") |
| 1265 |
path = graph.topologicalSort() |
| 1266 |
self.assertEqual(["3", "2", "1"], path) |
| 1267 |
|
| 1268 |
def testTopologicalSort_015(self): |
| 1269 |
""" |
| 1270 |
Graph with 3 vertices, in a chain (3->2->1), create order (2,3,1) |
| 1271 |
""" |
| 1272 |
graph = DirectedGraph("test") |
| 1273 |
graph.createVertex("2") |
| 1274 |
graph.createVertex("3") |
| 1275 |
graph.createVertex("1") |
| 1276 |
graph.createEdge("3", "2") |
| 1277 |
graph.createEdge("2", "1") |
| 1278 |
path = graph.topologicalSort() |
| 1279 |
self.assertEqual(["3", "2", "1"], path) |
| 1280 |
|
| 1281 |
def testTopologicalSort_016(self): |
| 1282 |
""" |
| 1283 |
Graph with 3 vertices, in a chain (3->2->1), create order (2,1,3) |
| 1284 |
""" |
| 1285 |
graph = DirectedGraph("test") |
| 1286 |
graph.createVertex("2") |
| 1287 |
graph.createVertex("1") |
| 1288 |
graph.createVertex("3") |
| 1289 |
graph.createEdge("3", "2") |
| 1290 |
graph.createEdge("2", "1") |
| 1291 |
path = graph.topologicalSort() |
| 1292 |
self.assertEqual(["3", "2", "1"], path) |
| 1293 |
|
| 1294 |
def testTopologicalSort_017(self): |
| 1295 |
""" |
| 1296 |
Graph with 3 vertices, in a chain (3->2->1), create order (3,1,2) |
| 1297 |
""" |
| 1298 |
graph = DirectedGraph("test") |
| 1299 |
graph.createVertex("3") |
| 1300 |
graph.createVertex("1") |
| 1301 |
graph.createVertex("2") |
| 1302 |
graph.createEdge("3", "2") |
| 1303 |
graph.createEdge("2", "1") |
| 1304 |
path = graph.topologicalSort() |
| 1305 |
self.assertEqual(["3", "2", "1"], path) |
| 1306 |
|
| 1307 |
def testTopologicalSort_018(self): |
| 1308 |
""" |
| 1309 |
Graph with 3 vertices, in a chain (3->2->1), create order (3,2,1) |
| 1310 |
""" |
| 1311 |
graph = DirectedGraph("test") |
| 1312 |
graph.createVertex("3") |
| 1313 |
graph.createVertex("2") |
| 1314 |
graph.createVertex("1") |
| 1315 |
graph.createEdge("3", "2") |
| 1316 |
graph.createEdge("2", "1") |
| 1317 |
path = graph.topologicalSort() |
| 1318 |
self.assertEqual(["3", "2", "1"], path) |
| 1319 |
|
| 1320 |
def testTopologicalSort_019(self): |
| 1321 |
""" |
| 1322 |
Graph with 3 vertices, chain and orphan (1->2,3), create order (1,2,3) |
| 1323 |
""" |
| 1324 |
graph = DirectedGraph("test") |
| 1325 |
graph.createVertex("1") |
| 1326 |
graph.createVertex("2") |
| 1327 |
graph.createVertex("3") |
| 1328 |
graph.createEdge("1", "2") |
| 1329 |
path = graph.topologicalSort() |
| 1330 |
self.assertEqual(["3", "1", "2"], path) |
| 1331 |
|
| 1332 |
def testTopologicalSort_020(self): |
| 1333 |
""" |
| 1334 |
Graph with 3 vertices, chain and orphan (1->2,3), create order (1,3,2) |
| 1335 |
""" |
| 1336 |
graph = DirectedGraph("test") |
| 1337 |
graph.createVertex("1") |
| 1338 |
graph.createVertex("3") |
| 1339 |
graph.createVertex("2") |
| 1340 |
graph.createEdge("1", "2") |
| 1341 |
path = graph.topologicalSort() |
| 1342 |
self.assertEqual(["3", "1", "2"], path) |
| 1343 |
|
| 1344 |
def testTopologicalSort_021(self): |
| 1345 |
""" |
| 1346 |
Graph with 3 vertices, chain and orphan (1->2,3), create order (2,3,1) |
| 1347 |
""" |
| 1348 |
graph = DirectedGraph("test") |
| 1349 |
graph.createVertex("2") |
| 1350 |
graph.createVertex("3") |
| 1351 |
graph.createVertex("1") |
| 1352 |
graph.createEdge("1", "2") |
| 1353 |
path = graph.topologicalSort() |
| 1354 |
self.assertEqual(["1", "3", "2"], path) |
| 1355 |
|
| 1356 |
def testTopologicalSort_022(self): |
| 1357 |
""" |
| 1358 |
Graph with 3 vertices, chain and orphan (1->2,3), create order (2,1,3) |
| 1359 |
""" |
| 1360 |
graph = DirectedGraph("test") |
| 1361 |
graph.createVertex("2") |
| 1362 |
graph.createVertex("1") |
| 1363 |
graph.createVertex("3") |
| 1364 |
graph.createEdge("1", "2") |
| 1365 |
path = graph.topologicalSort() |
| 1366 |
self.assertEqual(["3", "1", "2"], path) |
| 1367 |
|
| 1368 |
def testTopologicalSort_023(self): |
| 1369 |
""" |
| 1370 |
Graph with 3 vertices, chain and orphan (1->2,3), create order (3,1,2) |
| 1371 |
""" |
| 1372 |
graph = DirectedGraph("test") |
| 1373 |
graph.createVertex("3") |
| 1374 |
graph.createVertex("1") |
| 1375 |
graph.createVertex("2") |
| 1376 |
graph.createEdge("1", "2") |
| 1377 |
path = graph.topologicalSort() |
| 1378 |
self.assertEqual(["1", "2", "3"], path) |
| 1379 |
|
| 1380 |
def testTopologicalSort_024(self): |
| 1381 |
""" |
| 1382 |
Graph with 3 vertices, chain and orphan (1->2,3), create order (3,2,1) |
| 1383 |
""" |
| 1384 |
graph = DirectedGraph("test") |
| 1385 |
graph.createVertex("3") |
| 1386 |
graph.createVertex("2") |
| 1387 |
graph.createVertex("1") |
| 1388 |
graph.createEdge("1", "2") |
| 1389 |
path = graph.topologicalSort() |
| 1390 |
self.assertEqual(["1", "2", "3"], path) |
| 1391 |
|
| 1392 |
def testTopologicalSort_025(self): |
| 1393 |
""" |
| 1394 |
Graph with 3 vertices, chain and orphan (1->3,2), create order (1,2,3) |
| 1395 |
""" |
| 1396 |
graph = DirectedGraph("test") |
| 1397 |
graph.createVertex("1") |
| 1398 |
graph.createVertex("2") |
| 1399 |
graph.createVertex("3") |
| 1400 |
graph.createEdge("1", "3") |
| 1401 |
path = graph.topologicalSort() |
| 1402 |
self.assertEqual(["2", "1", "3"], path) |
| 1403 |
|
| 1404 |
def testTopologicalSort_026(self): |
| 1405 |
""" |
| 1406 |
Graph with 3 vertices, chain and orphan (1->3,2), create order (1,3,2) |
| 1407 |
""" |
| 1408 |
graph = DirectedGraph("test") |
| 1409 |
graph.createVertex("1") |
| 1410 |
graph.createVertex("3") |
| 1411 |
graph.createVertex("2") |
| 1412 |
graph.createEdge("1", "3") |
| 1413 |
path = graph.topologicalSort() |
| 1414 |
self.assertEqual(["2", "1", "3"], path) |
| 1415 |
|
| 1416 |
def testTopologicalSort_027(self): |
| 1417 |
""" |
| 1418 |
Graph with 3 vertices, chain and orphan (1->3,2), create order (2,3,1) |
| 1419 |
""" |
| 1420 |
graph = DirectedGraph("test") |
| 1421 |
graph.createVertex("2") |
| 1422 |
graph.createVertex("3") |
| 1423 |
graph.createVertex("1") |
| 1424 |
graph.createEdge("1", "3") |
| 1425 |
path = graph.topologicalSort() |
| 1426 |
self.assertEqual(["1", "3", "2"], path) |
| 1427 |
|
| 1428 |
def testTopologicalSort_028(self): |
| 1429 |
""" |
| 1430 |
Graph with 3 vertices, chain and orphan (1->3,2), create order (2,1,3) |
| 1431 |
""" |
| 1432 |
graph = DirectedGraph("test") |
| 1433 |
graph.createVertex("2") |
| 1434 |
graph.createVertex("1") |
| 1435 |
graph.createVertex("3") |
| 1436 |
graph.createEdge("1", "3") |
| 1437 |
path = graph.topologicalSort() |
| 1438 |
self.assertEqual(["1", "3", "2"], path) |
| 1439 |
|
| 1440 |
def testTopologicalSort_029(self): |
| 1441 |
""" |
| 1442 |
Graph with 3 vertices, chain and orphan (1->3,2), create order (3,1,2) |
| 1443 |
""" |
| 1444 |
graph = DirectedGraph("test") |
| 1445 |
graph.createVertex("3") |
| 1446 |
graph.createVertex("1") |
| 1447 |
graph.createVertex("2") |
| 1448 |
graph.createEdge("1", "3") |
| 1449 |
path = graph.topologicalSort() |
| 1450 |
self.assertEqual(["2", "1", "3"], path) |
| 1451 |
|
| 1452 |
def testTopologicalSort_030(self): |
| 1453 |
""" |
| 1454 |
Graph with 3 vertices, chain and orphan (1->3,2), create order (3,2,1) |
| 1455 |
""" |
| 1456 |
graph = DirectedGraph("test") |
| 1457 |
graph.createVertex("3") |
| 1458 |
graph.createVertex("2") |
| 1459 |
graph.createVertex("1") |
| 1460 |
graph.createEdge("1", "3") |
| 1461 |
path = graph.topologicalSort() |
| 1462 |
self.assertEqual(["1", "2", "3"], path) |
| 1463 |
|
| 1464 |
def testTopologicalSort_031(self): |
| 1465 |
""" |
| 1466 |
Graph with 3 vertices, chain and orphan (2->3,1), create order (1,2,3) |
| 1467 |
""" |
| 1468 |
graph = DirectedGraph("test") |
| 1469 |
graph.createVertex("1") |
| 1470 |
graph.createVertex("2") |
| 1471 |
graph.createVertex("3") |
| 1472 |
graph.createEdge("2", "3") |
| 1473 |
path = graph.topologicalSort() |
| 1474 |
self.assertEqual(["2", "3", "1"], path) |
| 1475 |
|
| 1476 |
def testTopologicalSort_032(self): |
| 1477 |
""" |
| 1478 |
Graph with 3 vertices, chain and orphan (2->3,1), create order (1,3,2) |
| 1479 |
""" |
| 1480 |
graph = DirectedGraph("test") |
| 1481 |
graph.createVertex("1") |
| 1482 |
graph.createVertex("3") |
| 1483 |
graph.createVertex("2") |
| 1484 |
graph.createEdge("2", "3") |
| 1485 |
path = graph.topologicalSort() |
| 1486 |
self.assertEqual(["2", "3", "1"], path) |
| 1487 |
|
| 1488 |
def testTopologicalSort_033(self): |
| 1489 |
""" |
| 1490 |
Graph with 3 vertices, chain and orphan (2->3,1), create order (2,3,1) |
| 1491 |
""" |
| 1492 |
graph = DirectedGraph("test") |
| 1493 |
graph.createVertex("2") |
| 1494 |
graph.createVertex("3") |
| 1495 |
graph.createVertex("1") |
| 1496 |
graph.createEdge("2", "3") |
| 1497 |
path = graph.topologicalSort() |
| 1498 |
self.assertEqual(["1", "2", "3"], path) |
| 1499 |
|
| 1500 |
def testTopologicalSort_034(self): |
| 1501 |
""" |
| 1502 |
Graph with 3 vertices, chain and orphan (2->3,1), create order (2,1,3) |
| 1503 |
""" |
| 1504 |
graph = DirectedGraph("test") |
| 1505 |
graph.createVertex("2") |
| 1506 |
graph.createVertex("1") |
| 1507 |
graph.createVertex("3") |
| 1508 |
graph.createEdge("2", "3") |
| 1509 |
path = graph.topologicalSort() |
| 1510 |
self.assertEqual(["1", "2", "3"], path) |
| 1511 |
|
| 1512 |
def testTopologicalSort_035(self): |
| 1513 |
""" |
| 1514 |
Graph with 3 vertices, chain and orphan (2->3,1), create order (3,1,2) |
| 1515 |
""" |
| 1516 |
graph = DirectedGraph("test") |
| 1517 |
graph.createVertex("3") |
| 1518 |
graph.createVertex("1") |
| 1519 |
graph.createVertex("2") |
| 1520 |
graph.createEdge("2", "3") |
| 1521 |
path = graph.topologicalSort() |
| 1522 |
self.assertEqual(["2", "1", "3"], path) |
| 1523 |
|
| 1524 |
def testTopologicalSort_036(self): |
| 1525 |
""" |
| 1526 |
Graph with 3 vertices, chain and orphan (2->3,1), create order (3,2,1) |
| 1527 |
""" |
| 1528 |
graph = DirectedGraph("test") |
| 1529 |
graph.createVertex("3") |
| 1530 |
graph.createVertex("2") |
| 1531 |
graph.createVertex("1") |
| 1532 |
graph.createEdge("2", "3") |
| 1533 |
path = graph.topologicalSort() |
| 1534 |
self.assertEqual(["1", "2", "3"], path) |
| 1535 |
|
| 1536 |
def testTopologicalSort_037(self): |
| 1537 |
""" |
| 1538 |
Graph with 3 vertices, chain and orphan (2->1,3), create order (1,2,3) |
| 1539 |
""" |
| 1540 |
graph = DirectedGraph("test") |
| 1541 |
graph.createVertex("1") |
| 1542 |
graph.createVertex("2") |
| 1543 |
graph.createVertex("3") |
| 1544 |
graph.createEdge("2", "1") |
| 1545 |
path = graph.topologicalSort() |
| 1546 |
self.assertEqual(["3", "2", "1"], path) |
| 1547 |
|
| 1548 |
def testTopologicalSort_038(self): |
| 1549 |
""" |
| 1550 |
Graph with 3 vertices, chain and orphan (2->1,3), create order (1,3,2) |
| 1551 |
""" |
| 1552 |
graph = DirectedGraph("test") |
| 1553 |
graph.createVertex("1") |
| 1554 |
graph.createVertex("3") |
| 1555 |
graph.createVertex("2") |
| 1556 |
graph.createEdge("2", "1") |
| 1557 |
path = graph.topologicalSort() |
| 1558 |
self.assertEqual(["2", "3", "1"], path) |
| 1559 |
|
| 1560 |
def testTopologicalSort_039(self): |
| 1561 |
""" |
| 1562 |
Graph with 3 vertices, chain and orphan (2->1,3), create order (2,3,1) |
| 1563 |
""" |
| 1564 |
graph = DirectedGraph("test") |
| 1565 |
graph.createVertex("2") |
| 1566 |
graph.createVertex("3") |
| 1567 |
graph.createVertex("1") |
| 1568 |
graph.createEdge("2", "1") |
| 1569 |
path = graph.topologicalSort() |
| 1570 |
self.assertEqual(["3", "2", "1"], path) |
| 1571 |
|
| 1572 |
def testTopologicalSort_040(self): |
| 1573 |
""" |
| 1574 |
Graph with 3 vertices, chain and orphan (2->1,3), create order (2,1,3) |
| 1575 |
""" |
| 1576 |
graph = DirectedGraph("test") |
| 1577 |
graph.createVertex("2") |
| 1578 |
graph.createVertex("1") |
| 1579 |
graph.createVertex("3") |
| 1580 |
graph.createEdge("2", "1") |
| 1581 |
path = graph.topologicalSort() |
| 1582 |
self.assertEqual(["3", "2", "1"], path) |
| 1583 |
|
| 1584 |
def testTopologicalSort_041(self): |
| 1585 |
""" |
| 1586 |
Graph with 3 vertices, chain and orphan (2->1,3), create order (3,1,2) |
| 1587 |
""" |
| 1588 |
graph = DirectedGraph("test") |
| 1589 |
graph.createVertex("3") |
| 1590 |
graph.createVertex("1") |
| 1591 |
graph.createVertex("2") |
| 1592 |
graph.createEdge("2", "1") |
| 1593 |
path = graph.topologicalSort() |
| 1594 |
self.assertEqual(["2", "1", "3"], path) |
| 1595 |
|
| 1596 |
def testTopologicalSort_042(self): |
| 1597 |
""" |
| 1598 |
Graph with 3 vertices, chain and orphan (2->1,3), create order (3,2,1) |
| 1599 |
""" |
| 1600 |
graph = DirectedGraph("test") |
| 1601 |
graph.createVertex("3") |
| 1602 |
graph.createVertex("2") |
| 1603 |
graph.createVertex("1") |
| 1604 |
graph.createEdge("2", "1") |
| 1605 |
path = graph.topologicalSort() |
| 1606 |
self.assertEqual(["2", "1", "3"], path) |
| 1607 |
|
| 1608 |
def testTopologicalSort_043(self): |
| 1609 |
""" |
| 1610 |
Graph with 3 vertices, chain and orphan (3->1,2), create order (1,2,3) |
| 1611 |
""" |
| 1612 |
graph = DirectedGraph("test") |
| 1613 |
graph.createVertex("1") |
| 1614 |
graph.createVertex("2") |
| 1615 |
graph.createVertex("3") |
| 1616 |
graph.createEdge("3", "1") |
| 1617 |
path = graph.topologicalSort() |
| 1618 |
self.assertEqual(["3", "2", "1"], path) |
| 1619 |
|
| 1620 |
def testTopologicalSort_044(self): |
| 1621 |
""" |
| 1622 |
Graph with 3 vertices, chain and orphan (3->1,2), create order (1,3,2) |
| 1623 |
""" |
| 1624 |
graph = DirectedGraph("test") |
| 1625 |
graph.createVertex("1") |
| 1626 |
graph.createVertex("3") |
| 1627 |
graph.createVertex("2") |
| 1628 |
graph.createEdge("3", "1") |
| 1629 |
path = graph.topologicalSort() |
| 1630 |
self.assertEqual(["2", "3", "1"], path) |
| 1631 |
|
| 1632 |
def testTopologicalSort_045(self): |
| 1633 |
""" |
| 1634 |
Graph with 3 vertices, chain and orphan (3->1,2), create order (2,3,1) |
| 1635 |
""" |
| 1636 |
graph = DirectedGraph("test") |
| 1637 |
graph.createVertex("2") |
| 1638 |
graph.createVertex("3") |
| 1639 |
graph.createVertex("1") |
| 1640 |
graph.createEdge("3", "1") |
| 1641 |
path = graph.topologicalSort() |
| 1642 |
self.assertEqual(["3", "1", "2"], path) |
| 1643 |
|
| 1644 |
def testTopologicalSort_046(self): |
| 1645 |
""" |
| 1646 |
Graph with 3 vertices, chain and orphan (3->1,2), create order (2,1,3) |
| 1647 |
""" |
| 1648 |
graph = DirectedGraph("test") |
| 1649 |
graph.createVertex("2") |
| 1650 |
graph.createVertex("1") |
| 1651 |
graph.createVertex("3") |
| 1652 |
graph.createEdge("3", "1") |
| 1653 |
path = graph.topologicalSort() |
| 1654 |
self.assertEqual(["3", "1", "2"], path) |
| 1655 |
|
| 1656 |
def testTopologicalSort_047(self): |
| 1657 |
""" |
| 1658 |
Graph with 3 vertices, chain and orphan (3->1,2), create order (3,1,2) |
| 1659 |
""" |
| 1660 |
graph = DirectedGraph("test") |
| 1661 |
graph.createVertex("3") |
| 1662 |
graph.createVertex("1") |
| 1663 |
graph.createVertex("2") |
| 1664 |
graph.createEdge("3", "1") |
| 1665 |
path = graph.topologicalSort() |
| 1666 |
self.assertEqual(["2", "3", "1"], path) |
| 1667 |
|
| 1668 |
def testTopologicalSort_048(self): |
| 1669 |
""" |
| 1670 |
Graph with 3 vertices, chain and orphan (3->1,2), create order (3,2,1) |
| 1671 |
""" |
| 1672 |
graph = DirectedGraph("test") |
| 1673 |
graph.createVertex("3") |
| 1674 |
graph.createVertex("2") |
| 1675 |
graph.createVertex("1") |
| 1676 |
graph.createEdge("3", "1") |
| 1677 |
path = graph.topologicalSort() |
| 1678 |
self.assertEqual(["2", "3", "1"], path) |
| 1679 |
|
| 1680 |
def testTopologicalSort_049(self): |
| 1681 |
""" |
| 1682 |
Graph with 3 vertices, chain and orphan (3->2,1), create order (1,2,3) |
| 1683 |
""" |
| 1684 |
graph = DirectedGraph("test") |
| 1685 |
graph.createVertex("1") |
| 1686 |
graph.createVertex("2") |
| 1687 |
graph.createVertex("3") |
| 1688 |
graph.createEdge("3", "2") |
| 1689 |
path = graph.topologicalSort() |
| 1690 |
self.assertEqual(["3", "2", "1"], path) |
| 1691 |
|
| 1692 |
def testTopologicalSort_050(self): |
| 1693 |
""" |
| 1694 |
Graph with 3 vertices, chain and orphan (3->2,1), create order (1,3,2) |
| 1695 |
""" |
| 1696 |
graph = DirectedGraph("test") |
| 1697 |
graph.createVertex("1") |
| 1698 |
graph.createVertex("3") |
| 1699 |
graph.createVertex("2") |
| 1700 |
graph.createEdge("3", "2") |
| 1701 |
path = graph.topologicalSort() |
| 1702 |
self.assertEqual(["3", "2", "1"], path) |
| 1703 |
|
| 1704 |
def testTopologicalSort_051(self): |
| 1705 |
""" |
| 1706 |
Graph with 3 vertices, chain and orphan (3->2,1), create order (2,3,1) |
| 1707 |
""" |
| 1708 |
graph = DirectedGraph("test") |
| 1709 |
graph.createVertex("2") |
| 1710 |
graph.createVertex("3") |
| 1711 |
graph.createVertex("1") |
| 1712 |
graph.createEdge("3", "2") |
| 1713 |
path = graph.topologicalSort() |
| 1714 |
self.assertEqual(["1", "3", "2"], path) |
| 1715 |
|
| 1716 |
def testTopologicalSort_052(self): |
| 1717 |
""" |
| 1718 |
Graph with 3 vertices, chain and orphan (3->2,1), create order (2,1,3) |
| 1719 |
""" |
| 1720 |
graph = DirectedGraph("test") |
| 1721 |
graph.createVertex("2") |
| 1722 |
graph.createVertex("1") |
| 1723 |
graph.createVertex("3") |
| 1724 |
graph.createEdge("3", "2") |
| 1725 |
path = graph.topologicalSort() |
| 1726 |
self.assertEqual(["3", "1", "2"], path) |
| 1727 |
|
| 1728 |
def testTopologicalSort_053(self): |
| 1729 |
""" |
| 1730 |
Graph with 3 vertices, chain and orphan (3->2,1), create order (3,1,2) |
| 1731 |
""" |
| 1732 |
graph = DirectedGraph("test") |
| 1733 |
graph.createVertex("3") |
| 1734 |
graph.createVertex("1") |
| 1735 |
graph.createVertex("2") |
| 1736 |
graph.createEdge("3", "2") |
| 1737 |
path = graph.topologicalSort() |
| 1738 |
self.assertEqual(["1", "3", "2"], path) |
| 1739 |
|
| 1740 |
def testTopologicalSort_054(self): |
| 1741 |
""" |
| 1742 |
Graph with 3 vertices, chain and orphan (3->2,1), create order (3,2,1) |
| 1743 |
""" |
| 1744 |
graph = DirectedGraph("test") |
| 1745 |
graph.createVertex("3") |
| 1746 |
graph.createVertex("2") |
| 1747 |
graph.createVertex("1") |
| 1748 |
graph.createEdge("3", "2") |
| 1749 |
path = graph.topologicalSort() |
| 1750 |
self.assertEqual(["1", "3", "2"], path) |
| 1751 |
|
| 1752 |
def testTopologicalSort_055(self): |
| 1753 |
""" |
| 1754 |
Graph with 1 vertex, with an edge to itself (1->1). |
| 1755 |
""" |
| 1756 |
graph = DirectedGraph("test") |
| 1757 |
graph.createVertex("1") |
| 1758 |
graph.createEdge("1", "1") |
| 1759 |
self.assertRaises(ValueError, graph.topologicalSort) |
| 1760 |
|
| 1761 |
def testTopologicalSort_056(self): |
| 1762 |
""" |
| 1763 |
Graph with 2 vertices, each with an edge to itself (1->1, 2->2). |
| 1764 |
""" |
| 1765 |
graph = DirectedGraph("test") |
| 1766 |
graph.createVertex("1") |
| 1767 |
graph.createVertex("2") |
| 1768 |
graph.createEdge("1", "1") |
| 1769 |
graph.createEdge("2", "2") |
| 1770 |
self.assertRaises(ValueError, graph.topologicalSort) |
| 1771 |
|
| 1772 |
def testTopologicalSort_057(self): |
| 1773 |
""" |
| 1774 |
Graph with 3 vertices, each with an edge to itself (1->1, 2->2, 3->3). |
| 1775 |
""" |
| 1776 |
graph = DirectedGraph("test") |
| 1777 |
graph.createVertex("1") |
| 1778 |
graph.createVertex("2") |
| 1779 |
graph.createVertex("3") |
| 1780 |
graph.createEdge("1", "1") |
| 1781 |
graph.createEdge("2", "2") |
| 1782 |
graph.createEdge("3", "3") |
| 1783 |
self.assertRaises(ValueError, graph.topologicalSort) |
| 1784 |
|
| 1785 |
def testTopologicalSort_058(self): |
| 1786 |
""" |
| 1787 |
Graph with 3 vertices, in a loop (1->2->3->1). |
| 1788 |
""" |
| 1789 |
graph = DirectedGraph("test") |
| 1790 |
graph.createVertex("1") |
| 1791 |
graph.createVertex("2") |
| 1792 |
graph.createVertex("3") |
| 1793 |
graph.createEdge("1", "2") |
| 1794 |
graph.createEdge("2", "3") |
| 1795 |
graph.createEdge("3", "1") |
| 1796 |
self.assertRaises(ValueError, graph.topologicalSort) |
| 1797 |
|
| 1798 |
def testTopologicalSort_059(self): |
| 1799 |
""" |
| 1800 |
Graph with 5 vertices, (2, 1->3, 1->4, 1->5) |
| 1801 |
""" |
| 1802 |
graph = DirectedGraph("test") |
| 1803 |
graph.createVertex("1") |
| 1804 |
graph.createVertex("2") |
| 1805 |
graph.createVertex("3") |
| 1806 |
graph.createVertex("4") |
| 1807 |
graph.createVertex("5") |
| 1808 |
graph.createEdge("1", "3") |
| 1809 |
graph.createEdge("1", "4") |
| 1810 |
graph.createEdge("1", "5") |
| 1811 |
path = graph.topologicalSort() |
| 1812 |
self.assertEqual(["2", "1", "5", "4", "3"], path) |
| 1813 |
|
| 1814 |
def testTopologicalSort_060(self): |
| 1815 |
""" |
| 1816 |
Graph with 5 vertices, (1->3, 1->4, 1->5, 2->5) |
| 1817 |
""" |
| 1818 |
graph = DirectedGraph("test") |
| 1819 |
graph.createVertex("1") |
| 1820 |
graph.createVertex("2") |
| 1821 |
graph.createVertex("3") |
| 1822 |
graph.createVertex("4") |
| 1823 |
graph.createVertex("5") |
| 1824 |
graph.createEdge("1", "3") |
| 1825 |
graph.createEdge("1", "4") |
| 1826 |
graph.createEdge("1", "5") |
| 1827 |
graph.createEdge("2", "5") |
| 1828 |
path = graph.topologicalSort() |
| 1829 |
self.assertEqual(["2", "1", "5", "4", "3"], path) |
| 1830 |
|
| 1831 |
def testTopologicalSort_061(self): |
| 1832 |
""" |
| 1833 |
Graph with 5 vertices, (1->3, 1->4, 1->5, 2->5, 3->4) |
| 1834 |
""" |
| 1835 |
graph = DirectedGraph("test") |
| 1836 |
graph.createVertex("1") |
| 1837 |
graph.createVertex("2") |
| 1838 |
graph.createVertex("3") |
| 1839 |
graph.createVertex("4") |
| 1840 |
graph.createVertex("5") |
| 1841 |
graph.createEdge("1", "3") |
| 1842 |
graph.createEdge("1", "4") |
| 1843 |
graph.createEdge("1", "5") |
| 1844 |
graph.createEdge("2", "5") |
| 1845 |
graph.createEdge("3", "4") |
| 1846 |
path = graph.topologicalSort() |
| 1847 |
self.assertEqual(["2", "1", "5", "3", "4"], path) |
| 1848 |
|
| 1849 |
def testTopologicalSort_062(self): |
| 1850 |
""" |
| 1851 |
Graph with 5 vertices, (1->3, 1->4, 1->5, 2->5, 3->4, 5->4) |
| 1852 |
""" |
| 1853 |
graph = DirectedGraph("test") |
| 1854 |
graph.createVertex("1") |
| 1855 |
graph.createVertex("2") |
| 1856 |
graph.createVertex("3") |
| 1857 |
graph.createVertex("4") |
| 1858 |
graph.createVertex("5") |
| 1859 |
graph.createEdge("1", "3") |
| 1860 |
graph.createEdge("1", "4") |
| 1861 |
graph.createEdge("1", "5") |
| 1862 |
graph.createEdge("2", "5") |
| 1863 |
graph.createEdge("3", "4") |
| 1864 |
graph.createEdge("5", "4") |
| 1865 |
path = graph.topologicalSort() |
| 1866 |
self.assertEqual(["2", "1", "5", "3", "4"], path) |
| 1867 |
|
| 1868 |
def testTopologicalSort_063(self): |
| 1869 |
""" |
| 1870 |
Graph with 5 vertices, (1->3, 1->4, 1->5, 2->5, 3->4, 5->4, 1->2) |
| 1871 |
""" |
| 1872 |
graph = DirectedGraph("test") |
| 1873 |
graph.createVertex("1") |
| 1874 |
graph.createVertex("2") |
| 1875 |
graph.createVertex("3") |
| 1876 |
graph.createVertex("4") |
| 1877 |
graph.createVertex("5") |
| 1878 |
graph.createEdge("1", "3") |
| 1879 |
graph.createEdge("1", "4") |
| 1880 |
graph.createEdge("1", "5") |
| 1881 |
graph.createEdge("2", "5") |
| 1882 |
graph.createEdge("3", "4") |
| 1883 |
graph.createEdge("5", "4") |
| 1884 |
graph.createEdge("1", "2") |
| 1885 |
path = graph.topologicalSort() |
| 1886 |
self.assertEqual(["1", "2", "5", "3", "4"], path) |
| 1887 |
|
| 1888 |
def testTopologicalSort_064(self): |
| 1889 |
""" |
| 1890 |
Graph with 5 vertices, (1->3, 1->4, 1->5, 2->5, 3->4, 5->4, 1->2, 3->5) |
| 1891 |
""" |
| 1892 |
graph = DirectedGraph("test") |
| 1893 |
graph.createVertex("1") |
| 1894 |
graph.createVertex("2") |
| 1895 |
graph.createVertex("3") |
| 1896 |
graph.createVertex("4") |
| 1897 |
graph.createVertex("5") |
| 1898 |
graph.createEdge("1", "3") |
| 1899 |
graph.createEdge("1", "4") |
| 1900 |
graph.createEdge("1", "5") |
| 1901 |
graph.createEdge("2", "5") |
| 1902 |
graph.createEdge("3", "4") |
| 1903 |
graph.createEdge("5", "4") |
| 1904 |
graph.createEdge("1", "2") |
| 1905 |
graph.createEdge("3", "5") |
| 1906 |
path = graph.topologicalSort() |
| 1907 |
self.assertEqual(["1", "2", "3", "5", "4"], path) |
| 1908 |
|
| 1909 |
def testTopologicalSort_065(self): |
| 1910 |
""" |
| 1911 |
Graph with 5 vertices, (1->3, 1->4, 1->5, 2->5, 3->4, 5->4, 5->1) |
| 1912 |
""" |
| 1913 |
graph = DirectedGraph("test") |
| 1914 |
graph.createVertex("1") |
| 1915 |
graph.createVertex("2") |
| 1916 |
graph.createVertex("3") |
| 1917 |
graph.createVertex("4") |
| 1918 |
graph.createVertex("5") |
| 1919 |
graph.createEdge("1", "3") |
| 1920 |
graph.createEdge("1", "4") |
| 1921 |
graph.createEdge("1", "5") |
| 1922 |
graph.createEdge("2", "5") |
| 1923 |
graph.createEdge("3", "4") |
| 1924 |
graph.createEdge("5", "4") |
| 1925 |
graph.createEdge("5", "1") |
| 1926 |
self.assertRaises(ValueError, graph.topologicalSort) |
| 1927 |
|
| 1928 |
|
| 1929 |
################################## |
| 1930 |
# TestPathResolverSingleton class |
| 1931 |
################################## |
| 1932 |
|
| 1933 |
|
| 1934 |
class TestPathResolverSingleton(unittest.TestCase): |
| 1935 |
"""Tests for the PathResolverSingleton class.""" |
| 1936 |
|
| 1937 |
################ |
| 1938 |
# Setup methods |
| 1939 |
################ |
| 1940 |
|
| 1941 |
def setUp(self): |
| 1942 |
pass |
| 1943 |
|
| 1944 |
def tearDown(self): |
| 1945 |
pass |
| 1946 |
|
| 1947 |
########################## |
| 1948 |
# Test singleton behavior |
| 1949 |
########################## |
| 1950 |
|
| 1951 |
def testBehavior_001(self): |
| 1952 |
""" |
| 1953 |
Check behavior of constructor around filling and clearing instance variable. |
| 1954 |
""" |
| 1955 |
PathResolverSingleton._instance = None |
| 1956 |
instance = PathResolverSingleton() |
| 1957 |
self.assertNotEqual(None, PathResolverSingleton._instance) |
| 1958 |
self.assertTrue(instance is PathResolverSingleton._instance) |
| 1959 |
|
| 1960 |
def testBehavior_002(self): |
| 1961 |
""" |
| 1962 |
Check behavior of getInstance() around filling and clearing instance variable. |
| 1963 |
""" |
| 1964 |
PathResolverSingleton._instance = None |
| 1965 |
instance1 = PathResolverSingleton.getInstance() |
| 1966 |
instance2 = PathResolverSingleton.getInstance() |
| 1967 |
instance3 = PathResolverSingleton.getInstance() |
| 1968 |
self.assertNotEqual(None, PathResolverSingleton._instance) |
| 1969 |
self.assertTrue(instance1 is PathResolverSingleton._instance) |
| 1970 |
self.assertTrue(instance1 is instance2) |
| 1971 |
self.assertTrue(instance1 is instance3) |
| 1972 |
|
| 1973 |
PathResolverSingleton._instance = None |
| 1974 |
PathResolverSingleton() |
| 1975 |
instance4 = PathResolverSingleton.getInstance() |
| 1976 |
instance5 = PathResolverSingleton.getInstance() |
| 1977 |
instance6 = PathResolverSingleton.getInstance() |
| 1978 |
self.assertTrue(instance1 is not instance4) |
| 1979 |
self.assertTrue(instance4 is PathResolverSingleton._instance) |
| 1980 |
self.assertTrue(instance4 is instance5) |
| 1981 |
self.assertTrue(instance4 is instance6) |
| 1982 |
|
| 1983 |
PathResolverSingleton._instance = None |
| 1984 |
instance7 = PathResolverSingleton.getInstance() |
| 1985 |
instance8 = PathResolverSingleton.getInstance() |
| 1986 |
instance9 = PathResolverSingleton.getInstance() |
| 1987 |
self.assertTrue(instance1 is not instance7) |
| 1988 |
self.assertTrue(instance4 is not instance7) |
| 1989 |
self.assertTrue(instance7 is PathResolverSingleton._instance) |
| 1990 |
self.assertTrue(instance7 is instance8) |
| 1991 |
self.assertTrue(instance7 is instance9) |
| 1992 |
|
| 1993 |
############################ |
| 1994 |
# Test lookup functionality |
| 1995 |
############################ |
| 1996 |
|
| 1997 |
def testLookup_001(self): |
| 1998 |
""" |
| 1999 |
Test that lookup() always returns default when singleton is empty. |
| 2000 |
""" |
| 2001 |
PathResolverSingleton._instance = None |
| 2002 |
instance = PathResolverSingleton.getInstance() |
| 2003 |
|
| 2004 |
result = instance.lookup("whatever") |
| 2005 |
self.assertEqual(result, None) |
| 2006 |
|
| 2007 |
result = instance.lookup("whatever", None) |
| 2008 |
self.assertEqual(result, None) |
| 2009 |
|
| 2010 |
result = instance.lookup("other") |
| 2011 |
self.assertEqual(result, None) |
| 2012 |
|
| 2013 |
result = instance.lookup("other", "default") |
| 2014 |
self.assertEqual(result, "default") |
| 2015 |
|
| 2016 |
def testLookup_002(self): |
| 2017 |
""" |
| 2018 |
Test that lookup() returns proper values when singleton is not empty. |
| 2019 |
""" |
| 2020 |
mappings = {"one": "/path/to/one", "two": "/path/to/two"} |
| 2021 |
PathResolverSingleton._instance = None |
| 2022 |
singleton = PathResolverSingleton() |
| 2023 |
singleton.fill(mappings) |
| 2024 |
|
| 2025 |
instance = PathResolverSingleton.getInstance() |
| 2026 |
|
| 2027 |
result = instance.lookup("whatever") |
| 2028 |
self.assertEqual(result, None) |
| 2029 |
|
| 2030 |
result = instance.lookup("whatever", None) |
| 2031 |
self.assertEqual(result, None) |
| 2032 |
|
| 2033 |
result = instance.lookup("other") |
| 2034 |
self.assertEqual(result, None) |
| 2035 |
|
| 2036 |
result = instance.lookup("other", "default") |
| 2037 |
self.assertEqual(result, "default") |
| 2038 |
|
| 2039 |
result = instance.lookup("one") |
| 2040 |
self.assertEqual(result, "/path/to/one") |
| 2041 |
|
| 2042 |
result = instance.lookup("one", None) |
| 2043 |
self.assertEqual(result, "/path/to/one") |
| 2044 |
|
| 2045 |
result = instance.lookup("two", None) |
| 2046 |
self.assertEqual(result, "/path/to/two") |
| 2047 |
|
| 2048 |
result = instance.lookup("two", "default") |
| 2049 |
self.assertEqual(result, "/path/to/two") |
| 2050 |
|
| 2051 |
|
| 2052 |
######################## |
| 2053 |
# TestDiagnostics class |
| 2054 |
######################## |
| 2055 |
|
| 2056 |
|
| 2057 |
class TestDiagnostics(unittest.TestCase): |
| 2058 |
"""Tests for the Diagnostics class.""" |
| 2059 |
|
| 2060 |
def testMethods_001(self): |
| 2061 |
""" |
| 2062 |
Test the version attribute. |
| 2063 |
""" |
| 2064 |
diagnostics = Diagnostics() |
| 2065 |
self.assertFalse(diagnostics.version is None) |
| 2066 |
self.assertNotEqual("", diagnostics.version) |
| 2067 |
|
| 2068 |
def testMethods_002(self): |
| 2069 |
""" |
| 2070 |
Test the interpreter attribute. |
| 2071 |
""" |
| 2072 |
diagnostics = Diagnostics() |
| 2073 |
self.assertFalse(diagnostics.interpreter is None) |
| 2074 |
self.assertNotEqual("", diagnostics.interpreter) |
| 2075 |
|
| 2076 |
def testMethods_003(self): |
| 2077 |
""" |
| 2078 |
Test the platform attribute. |
| 2079 |
""" |
| 2080 |
diagnostics = Diagnostics() |
| 2081 |
self.assertFalse(diagnostics.platform is None) |
| 2082 |
self.assertNotEqual("", diagnostics.platform) |
| 2083 |
|
| 2084 |
def testMethods_004(self): |
| 2085 |
""" |
| 2086 |
Test the encoding attribute. |
| 2087 |
""" |
| 2088 |
diagnostics = Diagnostics() |
| 2089 |
self.assertFalse(diagnostics.encoding is None) |
| 2090 |
self.assertNotEqual("", diagnostics.encoding) |
| 2091 |
|
| 2092 |
# noinspection PyStatementEffect |
| 2093 |
def testMethods_005(self): |
| 2094 |
""" |
| 2095 |
Test the locale attribute. |
| 2096 |
""" |
| 2097 |
diagnostics = Diagnostics() |
| 2098 |
diagnostics.locale # ruff: ignore[useless-expression] # might not be set, so just make sure method doesn't fail |
| 2099 |
|
| 2100 |
def testMethods_006(self): |
| 2101 |
""" |
| 2102 |
Test the getValues() method. |
| 2103 |
""" |
| 2104 |
diagnostics = Diagnostics() |
| 2105 |
values = diagnostics.getValues() |
| 2106 |
self.assertEqual(diagnostics.version, values["version"]) |
| 2107 |
self.assertEqual(diagnostics.interpreter, values["interpreter"]) |
| 2108 |
self.assertEqual(diagnostics.platform, values["platform"]) |
| 2109 |
self.assertEqual(diagnostics.encoding, values["encoding"]) |
| 2110 |
self.assertEqual(diagnostics.locale, values["locale"]) |
| 2111 |
self.assertEqual(diagnostics.timestamp, values["timestamp"]) |
| 2112 |
|
| 2113 |
def testMethods_007(self): |
| 2114 |
""" |
| 2115 |
Test the _buildDiagnosticLines() method. |
| 2116 |
""" |
| 2117 |
values = Diagnostics().getValues() |
| 2118 |
lines = Diagnostics()._buildDiagnosticLines() |
| 2119 |
self.assertEqual(len(values), len(lines)) |
| 2120 |
|
| 2121 |
def testMethods_008(self): |
| 2122 |
""" |
| 2123 |
Test the printDiagnostics() method. |
| 2124 |
""" |
| 2125 |
captureOutput(Diagnostics().printDiagnostics) |
| 2126 |
|
| 2127 |
def testMethods_009(self): |
| 2128 |
""" |
| 2129 |
Test the logDiagnostics() method. |
| 2130 |
""" |
| 2131 |
logger = logging.getLogger("CedarBackup3.test") |
| 2132 |
Diagnostics().logDiagnostics(logger.info) |
| 2133 |
|
| 2134 |
def testMethods_010(self): |
| 2135 |
""" |
| 2136 |
Test the timestamp attribute. |
| 2137 |
""" |
| 2138 |
diagnostics = Diagnostics() |
| 2139 |
self.assertFalse(diagnostics.timestamp is None) |
| 2140 |
self.assertNotEqual("", diagnostics.timestamp) |
| 2141 |
|
| 2142 |
|
| 2143 |
###################### |
| 2144 |
# TestFunctions class |
| 2145 |
###################### |
| 2146 |
|
| 2147 |
|
| 2148 |
# noinspection PyUnusedLocal,PyShadowingBuiltins |
| 2149 |
class TestFunctions(unittest.TestCase): |
| 2150 |
"""Tests for the various public functions.""" |
| 2151 |
|
| 2152 |
################ |
| 2153 |
# Setup methods |
| 2154 |
################ |
| 2155 |
|
| 2156 |
def setUp(self): |
| 2157 |
try: |
| 2158 |
self.tmpdir = tempfile.mkdtemp() |
| 2159 |
self.resources = findResources(RESOURCES, DATA_DIRS) |
| 2160 |
except Exception as e: |
| 2161 |
self.fail(e) |
| 2162 |
|
| 2163 |
def tearDown(self): |
| 2164 |
removedir(self.tmpdir) |
| 2165 |
|
| 2166 |
################## |
| 2167 |
# Utility methods |
| 2168 |
################## |
| 2169 |
|
| 2170 |
def getTempfile(self): |
| 2171 |
"""Gets a path to a temporary file on disk.""" |
| 2172 |
(fd, name) = tempfile.mkstemp(dir=self.tmpdir) |
| 2173 |
try: |
| 2174 |
os.close(fd) |
| 2175 |
except: |
| 2176 |
pass |
| 2177 |
return name |
| 2178 |
|
| 2179 |
def extractTar(self, tarname): |
| 2180 |
"""Extracts a tarfile with a particular name.""" |
| 2181 |
extractTar(self.tmpdir, self.resources["%s.tar.gz" % tarname]) |
| 2182 |
|
| 2183 |
def buildPath(self, components): |
| 2184 |
"""Builds a complete search path from a list of components.""" |
| 2185 |
components.insert(0, self.tmpdir) |
| 2186 |
return buildPath(components) |
| 2187 |
|
| 2188 |
################## |
| 2189 |
# Test sortDict() |
| 2190 |
################## |
| 2191 |
|
| 2192 |
def testSortDict_001(self): |
| 2193 |
""" |
| 2194 |
Test for empty dictionary. |
| 2195 |
""" |
| 2196 |
d = {} |
| 2197 |
result = sortDict(d) |
| 2198 |
self.assertEqual([], result) |
| 2199 |
|
| 2200 |
def testSortDict_002(self): |
| 2201 |
""" |
| 2202 |
Test for dictionary with one item. |
| 2203 |
""" |
| 2204 |
d = {"a": 1} |
| 2205 |
result = sortDict(d) |
| 2206 |
self.assertEqual(["a"], result) |
| 2207 |
|
| 2208 |
def testSortDict_003(self): |
| 2209 |
""" |
| 2210 |
Test for dictionary with two items, same value. |
| 2211 |
""" |
| 2212 |
d = { |
| 2213 |
"a": 1, |
| 2214 |
"b": 1, |
| 2215 |
} |
| 2216 |
result = sortDict(d) |
| 2217 |
self.assertEqual(["a", "b"], result) |
| 2218 |
|
| 2219 |
def testSortDict_004(self): |
| 2220 |
""" |
| 2221 |
Test for dictionary with two items, different values. |
| 2222 |
""" |
| 2223 |
d = { |
| 2224 |
"a": 1, |
| 2225 |
"b": 2, |
| 2226 |
} |
| 2227 |
result = sortDict(d) |
| 2228 |
self.assertEqual(["a", "b"], result) |
| 2229 |
|
| 2230 |
def testSortDict_005(self): |
| 2231 |
""" |
| 2232 |
Test for dictionary with many items, same and different values. |
| 2233 |
""" |
| 2234 |
d = {"rebuild": 0, "purge": 400, "collect": 100, "validate": 0, "store": 300, "stage": 200} |
| 2235 |
result = sortDict(d) |
| 2236 |
self.assertEqual(["rebuild", "validate", "collect", "stage", "store", "purge"], result) |
| 2237 |
|
| 2238 |
############################## |
| 2239 |
# Test getFunctionReference() |
| 2240 |
############################## |
| 2241 |
|
| 2242 |
def testGetFunctionReference_001(self): |
| 2243 |
""" |
| 2244 |
Check that the search works within "standard" Python namespace. |
| 2245 |
""" |
| 2246 |
module = "os.path" |
| 2247 |
function = "isdir" |
| 2248 |
reference = getFunctionReference(module, function) |
| 2249 |
self.assertTrue(isdir is reference) |
| 2250 |
|
| 2251 |
def testGetFunctionReference_002(self): |
| 2252 |
""" |
| 2253 |
Check that the search works for things within CedarBackup3, legitimately callable. |
| 2254 |
""" |
| 2255 |
module = "CedarBackup3.util" |
| 2256 |
function = "executeCommand" |
| 2257 |
reference = getFunctionReference(module, function) |
| 2258 |
self.assertTrue(executeCommand is reference) |
| 2259 |
|
| 2260 |
def testGetFunctionReference_003(self): |
| 2261 |
""" |
| 2262 |
Check that the search works for things within CedarBackup3, not callable. |
| 2263 |
""" |
| 2264 |
module = "CedarBackup3.util" |
| 2265 |
function = "SECONDS_PER_MINUTE" |
| 2266 |
try: |
| 2267 |
getFunctionReference(module, function) |
| 2268 |
self.fail("Did not get expected ValueError") |
| 2269 |
except ValueError: |
| 2270 |
pass |
| 2271 |
|
| 2272 |
def testGetFunctionReference_004(self): |
| 2273 |
""" |
| 2274 |
Check that the search works for things within CedarBackup3, not found. |
| 2275 |
""" |
| 2276 |
module = "CedarBackup3.util" |
| 2277 |
function = "BOGUS" |
| 2278 |
try: |
| 2279 |
getFunctionReference(module, function) |
| 2280 |
self.fail("Did not get expected AttributeError") |
| 2281 |
except AttributeError: |
| 2282 |
pass |
| 2283 |
|
| 2284 |
######################## |
| 2285 |
# Test resolveCommand() |
| 2286 |
######################## |
| 2287 |
|
| 2288 |
def testResolveCommand_001(self): |
| 2289 |
""" |
| 2290 |
Test that the command is echoed back unchanged when singleton is empty. |
| 2291 |
""" |
| 2292 |
PathResolverSingleton._instance = None |
| 2293 |
|
| 2294 |
command = [ |
| 2295 |
"BAD", |
| 2296 |
] |
| 2297 |
expected = command[:] # ruff: ignore[slice-copy] |
| 2298 |
result = resolveCommand(command) |
| 2299 |
self.assertEqual(expected, result) |
| 2300 |
|
| 2301 |
command = [ |
| 2302 |
"GOOD", |
| 2303 |
] |
| 2304 |
expected = command[:] |
| 2305 |
result = resolveCommand(command) |
| 2306 |
self.assertEqual(expected, result) |
| 2307 |
|
| 2308 |
command = [ |
| 2309 |
"WHATEVER", |
| 2310 |
"--verbose", |
| 2311 |
"--debug", |
| 2312 |
"tvh:asa892831", |
| 2313 |
"blech", |
| 2314 |
"<", |
| 2315 |
] |
| 2316 |
expected = command[:] |
| 2317 |
result = resolveCommand(command) |
| 2318 |
self.assertEqual(expected, result) |
| 2319 |
|
| 2320 |
def testResolveCommand_002(self): |
| 2321 |
""" |
| 2322 |
Test that the command is echoed back unchanged when mapping is not found. |
| 2323 |
""" |
| 2324 |
PathResolverSingleton._instance = None |
| 2325 |
mappings = {"one": "/path/to/one", "two": "/path/to/two"} |
| 2326 |
singleton = PathResolverSingleton() |
| 2327 |
singleton.fill(mappings) |
| 2328 |
|
| 2329 |
command = [ |
| 2330 |
"BAD", |
| 2331 |
] |
| 2332 |
expected = command[:] # ruff: ignore[slice-copy] |
| 2333 |
result = resolveCommand(command) |
| 2334 |
self.assertEqual(expected, result) |
| 2335 |
|
| 2336 |
command = [ |
| 2337 |
"GOOD", |
| 2338 |
] |
| 2339 |
expected = command[:] |
| 2340 |
result = resolveCommand(command) |
| 2341 |
self.assertEqual(expected, result) |
| 2342 |
|
| 2343 |
command = [ |
| 2344 |
"WHATEVER", |
| 2345 |
"--verbose", |
| 2346 |
"--debug", |
| 2347 |
"tvh:asa892831", |
| 2348 |
"blech", |
| 2349 |
"<", |
| 2350 |
] |
| 2351 |
expected = command[:] |
| 2352 |
result = resolveCommand(command) |
| 2353 |
self.assertEqual(expected, result) |
| 2354 |
|
| 2355 |
def testResolveCommand_003(self): |
| 2356 |
""" |
| 2357 |
Test that the command is echoed back changed appropriately when mapping is found. |
| 2358 |
""" |
| 2359 |
PathResolverSingleton._instance = None |
| 2360 |
mappings = {"one": "/path/to/one", "two": "/path/to/two"} |
| 2361 |
singleton = PathResolverSingleton() |
| 2362 |
singleton.fill(mappings) |
| 2363 |
|
| 2364 |
command = [ |
| 2365 |
"one", |
| 2366 |
] |
| 2367 |
expected = [ |
| 2368 |
"/path/to/one", |
| 2369 |
] |
| 2370 |
result = resolveCommand(command) |
| 2371 |
self.assertEqual(expected, result) |
| 2372 |
|
| 2373 |
command = [ |
| 2374 |
"two", |
| 2375 |
] |
| 2376 |
expected = [ |
| 2377 |
"/path/to/two", |
| 2378 |
] |
| 2379 |
result = resolveCommand(command) |
| 2380 |
self.assertEqual(expected, result) |
| 2381 |
|
| 2382 |
command = [ |
| 2383 |
"two", |
| 2384 |
"--verbose", |
| 2385 |
"--debug", |
| 2386 |
"tvh:asa892831", |
| 2387 |
"blech", |
| 2388 |
"<", |
| 2389 |
] |
| 2390 |
expected = [ |
| 2391 |
"/path/to/two", |
| 2392 |
"--verbose", |
| 2393 |
"--debug", |
| 2394 |
"tvh:asa892831", |
| 2395 |
"blech", |
| 2396 |
"<", |
| 2397 |
] |
| 2398 |
result = resolveCommand(command) |
| 2399 |
self.assertEqual(expected, result) |
| 2400 |
|
| 2401 |
######################## |
| 2402 |
# Test executeCommand() |
| 2403 |
######################## |
| 2404 |
|
| 2405 |
def testExecuteCommand_001(self): |
| 2406 |
""" |
| 2407 |
Execute a command that should succeed, no arguments, returnOutput=False |
| 2408 |
Command-line: non-Python platform-specific valid command |
| 2409 |
""" |
| 2410 |
command = VALID_COMMAND |
| 2411 |
args = VALID_ARGS |
| 2412 |
(result, output) = executeCommand(command, args, returnOutput=False) |
| 2413 |
self.assertEqual(0, result) |
| 2414 |
self.assertEqual(None, output) |
| 2415 |
|
| 2416 |
def testExecuteCommand_002(self): |
| 2417 |
""" |
| 2418 |
Execute a command that should succeed, one argument, returnOutput=False |
| 2419 |
Command-line: python -V |
| 2420 |
""" |
| 2421 |
command = [ |
| 2422 |
sys.executable, |
| 2423 |
] |
| 2424 |
args = [ |
| 2425 |
"-V", |
| 2426 |
] |
| 2427 |
(result, output) = executeCommand(command, args, returnOutput=False) |
| 2428 |
self.assertEqual(0, result) |
| 2429 |
self.assertEqual(None, output) |
| 2430 |
|
| 2431 |
def testExecuteCommand_003(self): |
| 2432 |
""" |
| 2433 |
Execute a command that should succeed, two arguments, returnOutput=False |
| 2434 |
Command-line: python -c "import sys; print(sys.argv[1:]); sys.exit(0)" |
| 2435 |
""" |
| 2436 |
command = [ |
| 2437 |
sys.executable, |
| 2438 |
] |
| 2439 |
args = [ |
| 2440 |
"-c", |
| 2441 |
"import sys; print(sys.argv[1:]); sys.exit(0)", |
| 2442 |
] |
| 2443 |
(result, output) = executeCommand(command, args, returnOutput=False) |
| 2444 |
self.assertEqual(0, result) |
| 2445 |
self.assertEqual(None, output) |
| 2446 |
|
| 2447 |
def testExecuteCommand_004(self): |
| 2448 |
""" |
| 2449 |
Execute a command that should succeed, three arguments, returnOutput=False |
| 2450 |
Command-line: python -c "import sys; print(sys.argv[1:]); sys.exit(0)" first |
| 2451 |
""" |
| 2452 |
command = [ |
| 2453 |
sys.executable, |
| 2454 |
] |
| 2455 |
args = [ |
| 2456 |
"-c", |
| 2457 |
"import sys; print(sys.argv[1:]); sys.exit(0)", |
| 2458 |
"first", |
| 2459 |
] |
| 2460 |
(result, output) = executeCommand(command, args, returnOutput=False) |
| 2461 |
self.assertEqual(0, result) |
| 2462 |
self.assertEqual(None, output) |
| 2463 |
|
| 2464 |
def testExecuteCommand_005(self): |
| 2465 |
""" |
| 2466 |
Execute a command that should succeed, four arguments, returnOutput=False |
| 2467 |
Command-line: python -c "import sys; print(sys.argv[1:]); sys.exit(0)" first second |
| 2468 |
""" |
| 2469 |
command = [ |
| 2470 |
sys.executable, |
| 2471 |
] |
| 2472 |
args = [ |
| 2473 |
"-c", |
| 2474 |
"import sys; print(sys.argv[1:]); sys.exit(0)", |
| 2475 |
"first", |
| 2476 |
"second", |
| 2477 |
] |
| 2478 |
(result, output) = executeCommand(command, args, returnOutput=False) |
| 2479 |
self.assertEqual(0, result) |
| 2480 |
self.assertEqual(None, output) |
| 2481 |
|
| 2482 |
def testExecuteCommand_006(self): |
| 2483 |
""" |
| 2484 |
Execute a command that should fail, returnOutput=False |
| 2485 |
Command-line: python -c "import sys; print(sys.argv[1:]); sys.exit(1)" |
| 2486 |
""" |
| 2487 |
command = [ |
| 2488 |
sys.executable, |
| 2489 |
] |
| 2490 |
args = [ |
| 2491 |
"-c", |
| 2492 |
"import sys; print(sys.argv[1:]); sys.exit(1)", |
| 2493 |
] |
| 2494 |
(result, output) = executeCommand(command, args, returnOutput=False) |
| 2495 |
self.assertNotEqual(0, result) |
| 2496 |
self.assertEqual(None, output) |
| 2497 |
|
| 2498 |
def testExecuteCommand_007(self): |
| 2499 |
""" |
| 2500 |
Execute a command that should fail, more arguments, returnOutput=False |
| 2501 |
Command-line: python -c "import sys; print(sys.argv[1:]); sys.exit(1)" first second |
| 2502 |
""" |
| 2503 |
command = [ |
| 2504 |
sys.executable, |
| 2505 |
] |
| 2506 |
args = [ |
| 2507 |
"-c", |
| 2508 |
"import sys; print(sys.argv[1:]); sys.exit(1)", |
| 2509 |
"first", |
| 2510 |
"second", |
| 2511 |
] |
| 2512 |
(result, output) = executeCommand(command, args, returnOutput=False) |
| 2513 |
self.assertNotEqual(0, result) |
| 2514 |
self.assertEqual(None, output) |
| 2515 |
|
| 2516 |
def testExecuteCommand_008(self): |
| 2517 |
""" |
| 2518 |
Execute a command that should succeed, no arguments, returnOutput=True |
| 2519 |
Command-line: non-Python platform-specific valid command |
| 2520 |
""" |
| 2521 |
command = VALID_COMMAND |
| 2522 |
args = VALID_ARGS |
| 2523 |
(result, output) = executeCommand(command, args, returnOutput=True) |
| 2524 |
self.assertEqual(0, result) |
| 2525 |
self.assertEqual(1, len(output)) |
| 2526 |
self.assertEqual(VALID_OUTPUT, output[0]) |
| 2527 |
|
| 2528 |
def testExecuteCommand_009(self): |
| 2529 |
""" |
| 2530 |
Execute a command that should succeed, one argument, returnOutput=True |
| 2531 |
Command-line: python -V |
| 2532 |
""" |
| 2533 |
command = [ |
| 2534 |
sys.executable, |
| 2535 |
] |
| 2536 |
args = [ |
| 2537 |
"-V", |
| 2538 |
] |
| 2539 |
(result, output) = executeCommand(command, args, returnOutput=True) |
| 2540 |
self.assertEqual(0, result) |
| 2541 |
self.assertEqual(1, len(output)) |
| 2542 |
self.assertTrue(output[0].startswith("Python")) |
| 2543 |
|
| 2544 |
def testExecuteCommand_010(self): |
| 2545 |
""" |
| 2546 |
Execute a command that should succeed, two arguments, returnOutput=True |
| 2547 |
Command-line: python -c "import sys; print(''); sys.exit(0)" |
| 2548 |
""" |
| 2549 |
command = [ |
| 2550 |
sys.executable, |
| 2551 |
] |
| 2552 |
args = [ |
| 2553 |
"-c", |
| 2554 |
"import sys; print(''); sys.exit(0)", |
| 2555 |
] |
| 2556 |
(result, output) = executeCommand(command, args, returnOutput=True) |
| 2557 |
self.assertEqual(0, result) |
| 2558 |
self.assertEqual(1, len(output)) |
| 2559 |
self.assertEqual(os.linesep, output[0]) |
| 2560 |
|
| 2561 |
def testExecuteCommand_011(self): |
| 2562 |
""" |
| 2563 |
Execute a command that should succeed, three arguments, returnOutput=True |
| 2564 |
Command-line: python -c "import sys; print('%s' % (sys.argv[1])); sys.exit(0)" first |
| 2565 |
""" |
| 2566 |
command = [ |
| 2567 |
sys.executable, |
| 2568 |
] |
| 2569 |
args = [ |
| 2570 |
"-c", |
| 2571 |
"import sys; print('%s' % (sys.argv[1])); sys.exit(0)", |
| 2572 |
"first", |
| 2573 |
] |
| 2574 |
(result, output) = executeCommand(command, args, returnOutput=True) |
| 2575 |
self.assertEqual(0, result) |
| 2576 |
self.assertEqual(1, len(output)) |
| 2577 |
self.assertEqual("first%s" % os.linesep, output[0]) |
| 2578 |
|
| 2579 |
def testExecuteCommand_012(self): |
| 2580 |
""" |
| 2581 |
Execute a command that should succeed, four arguments, returnOutput=True |
| 2582 |
Command-line: python -c "import sys; print('%s' % sys.argv[1]); print('%s' % sys.argv[2]); sys.exit(0)" first second |
| 2583 |
""" |
| 2584 |
command = [ |
| 2585 |
sys.executable, |
| 2586 |
] |
| 2587 |
args = [ |
| 2588 |
"-c", |
| 2589 |
"import sys; print('%s' % sys.argv[1]); print('%s' % sys.argv[2]); sys.exit(0)", |
| 2590 |
"first", |
| 2591 |
"second", |
| 2592 |
] |
| 2593 |
(result, output) = executeCommand(command, args, returnOutput=True) |
| 2594 |
self.assertEqual(0, result) |
| 2595 |
self.assertEqual(2, len(output)) |
| 2596 |
self.assertEqual("first%s" % os.linesep, output[0]) |
| 2597 |
self.assertEqual("second%s" % os.linesep, output[1]) |
| 2598 |
|
| 2599 |
def testExecuteCommand_013(self): |
| 2600 |
""" |
| 2601 |
Execute a command that should fail, returnOutput=True |
| 2602 |
Command-line: python -c "import sys; print(''); sys.exit(1)" |
| 2603 |
""" |
| 2604 |
command = [ |
| 2605 |
sys.executable, |
| 2606 |
] |
| 2607 |
args = [ |
| 2608 |
"-c", |
| 2609 |
"import sys; print(''); sys.exit(1)", |
| 2610 |
] |
| 2611 |
(result, output) = executeCommand(command, args, returnOutput=True) |
| 2612 |
self.assertNotEqual(0, result) |
| 2613 |
self.assertEqual(1, len(output)) |
| 2614 |
self.assertEqual(os.linesep, output[0]) |
| 2615 |
|
| 2616 |
def testExecuteCommand_014(self): |
| 2617 |
""" |
| 2618 |
Execute a command that should fail, more arguments, returnOutput=True |
| 2619 |
Command-line: python -c "import sys; print('%s' % sys.argv[1]); print('%s' % sys.argv[2]); sys.exit(1)" first second |
| 2620 |
""" |
| 2621 |
command = [ |
| 2622 |
sys.executable, |
| 2623 |
] |
| 2624 |
args = [ |
| 2625 |
"-c", |
| 2626 |
"import sys; print('%s' % sys.argv[1]); print('%s' % sys.argv[2]); sys.exit(1)", |
| 2627 |
"first", |
| 2628 |
"second", |
| 2629 |
] |
| 2630 |
(result, output) = executeCommand(command, args, returnOutput=True) |
| 2631 |
self.assertNotEqual(0, result) |
| 2632 |
self.assertEqual(2, len(output)) |
| 2633 |
self.assertEqual("first%s" % os.linesep, output[0]) |
| 2634 |
self.assertEqual("second%s" % os.linesep, output[1]) |
| 2635 |
|
| 2636 |
def testExecuteCommand_015(self): |
| 2637 |
""" |
| 2638 |
Execute a command that should succeed, no arguments, returnOutput=False |
| 2639 |
Do this all bundled into the command list, just to check that this works as expected. |
| 2640 |
Command-line: non-Python platform-specific valid command |
| 2641 |
""" |
| 2642 |
command = VALID_COMMAND |
| 2643 |
args = VALID_ARGS |
| 2644 |
(result, output) = executeCommand(command, args, returnOutput=False) |
| 2645 |
self.assertEqual(0, result) |
| 2646 |
self.assertEqual(None, output) |
| 2647 |
|
| 2648 |
def testExecuteCommand_016(self): |
| 2649 |
""" |
| 2650 |
Execute a command that should succeed, one argument, returnOutput=False |
| 2651 |
Do this all bundled into the command list, just to check that this works as expected. |
| 2652 |
Command-line: python -V |
| 2653 |
""" |
| 2654 |
command = [ |
| 2655 |
sys.executable, |
| 2656 |
"-V", |
| 2657 |
] |
| 2658 |
args = [] |
| 2659 |
(result, output) = executeCommand(command, args, returnOutput=False) |
| 2660 |
self.assertEqual(0, result) |
| 2661 |
self.assertEqual(None, output) |
| 2662 |
|
| 2663 |
def testExecuteCommand_017(self): |
| 2664 |
""" |
| 2665 |
Execute a command that should succeed, two arguments, returnOutput=False |
| 2666 |
Do this all bundled into the command list, just to check that this works as expected. |
| 2667 |
Command-line: python -c "import sys; print(sys.argv[1:]); sys.exit(0)" |
| 2668 |
""" |
| 2669 |
command = [ |
| 2670 |
sys.executable, |
| 2671 |
"-c", |
| 2672 |
"import sys; print(sys.argv[1:]); sys.exit(0)", |
| 2673 |
] |
| 2674 |
args = [] |
| 2675 |
(result, output) = executeCommand(command, args, returnOutput=False) |
| 2676 |
self.assertEqual(0, result) |
| 2677 |
self.assertEqual(None, output) |
| 2678 |
|
| 2679 |
def testExecuteCommand_018(self): |
| 2680 |
""" |
| 2681 |
Execute a command that should succeed, three arguments, returnOutput=False |
| 2682 |
Do this all bundled into the command list, just to check that this works as expected. |
| 2683 |
Command-line: python -c "import sys; print(sys.argv[1:]); sys.exit(0)" first |
| 2684 |
""" |
| 2685 |
command = [ |
| 2686 |
sys.executable, |
| 2687 |
"-c", |
| 2688 |
"import sys; print(sys.argv[1:]); sys.exit(0)", |
| 2689 |
"first", |
| 2690 |
] |
| 2691 |
args = [] |
| 2692 |
(result, output) = executeCommand(command, args, returnOutput=False) |
| 2693 |
self.assertEqual(0, result) |
| 2694 |
self.assertEqual(None, output) |
| 2695 |
|
| 2696 |
def testExecuteCommand_019(self): |
| 2697 |
""" |
| 2698 |
Execute a command that should succeed, four arguments, returnOutput=False |
| 2699 |
Do this all bundled into the command list, just to check that this works as expected. |
| 2700 |
Command-line: python -c "import sys; print(sys.argv[1:]); sys.exit(0)" first second |
| 2701 |
""" |
| 2702 |
command = [ |
| 2703 |
sys.executable, |
| 2704 |
"-c", |
| 2705 |
"import sys; print(sys.argv[1:]); sys.exit(0)", |
| 2706 |
"first", |
| 2707 |
"second", |
| 2708 |
] |
| 2709 |
args = [] |
| 2710 |
(result, output) = executeCommand(command, args, returnOutput=False) |
| 2711 |
self.assertEqual(0, result) |
| 2712 |
self.assertEqual(None, output) |
| 2713 |
|
| 2714 |
def testExecuteCommand_020(self): |
| 2715 |
""" |
| 2716 |
Execute a command that should fail, returnOutput=False |
| 2717 |
Do this all bundled into the command list, just to check that this works as expected. |
| 2718 |
Command-line: python -c "import sys; print(sys.argv[1:]); sys.exit(1)" |
| 2719 |
""" |
| 2720 |
command = [ |
| 2721 |
sys.executable, |
| 2722 |
"-c", |
| 2723 |
"import sys; print(sys.argv[1:]); sys.exit(1)", |
| 2724 |
] |
| 2725 |
args = [] |
| 2726 |
(result, output) = executeCommand(command, args, returnOutput=False) |
| 2727 |
self.assertNotEqual(0, result) |
| 2728 |
self.assertEqual(None, output) |
| 2729 |
|
| 2730 |
def testExecuteCommand_021(self): |
| 2731 |
""" |
| 2732 |
Execute a command that should fail, more arguments, returnOutput=False |
| 2733 |
Do this all bundled into the command list, just to check that this works as expected. |
| 2734 |
Command-line: python -c "import sys; print(sys.argv[1:]); sys.exit(1)" first second |
| 2735 |
""" |
| 2736 |
command = [ |
| 2737 |
sys.executable, |
| 2738 |
"-c", |
| 2739 |
"import sys; print(sys.argv[1:]); sys.exit(1)", |
| 2740 |
"first", |
| 2741 |
"second", |
| 2742 |
] |
| 2743 |
args = [] |
| 2744 |
(result, output) = executeCommand(command, args, returnOutput=False) |
| 2745 |
self.assertNotEqual(0, result) |
| 2746 |
self.assertEqual(None, output) |
| 2747 |
|
| 2748 |
def testExecuteCommand_022(self): |
| 2749 |
""" |
| 2750 |
Execute a command that should succeed, no arguments, returnOutput=True |
| 2751 |
Do this all bundled into the command list, just to check that this works as expected. |
| 2752 |
Command-line: non-Python platform-specific valid command |
| 2753 |
""" |
| 2754 |
command = VALID_COMMAND |
| 2755 |
args = VALID_ARGS |
| 2756 |
(result, output) = executeCommand(command, args, returnOutput=True) |
| 2757 |
self.assertEqual(0, result) |
| 2758 |
self.assertEqual(1, len(output)) |
| 2759 |
self.assertEqual(VALID_OUTPUT, output[0]) |
| 2760 |
|
| 2761 |
def testExecuteCommand_023(self): |
| 2762 |
""" |
| 2763 |
Execute a command that should succeed, one argument, returnOutput=True |
| 2764 |
Do this all bundled into the command list, just to check that this works as expected. |
| 2765 |
Command-line: python -V |
| 2766 |
""" |
| 2767 |
command = [sys.executable, "-V"] |
| 2768 |
args = [] |
| 2769 |
(result, output) = executeCommand(command, args, returnOutput=True) |
| 2770 |
self.assertEqual(0, result) |
| 2771 |
self.assertEqual(1, len(output)) |
| 2772 |
self.assertTrue(output[0].startswith("Python")) |
| 2773 |
|
| 2774 |
def testExecuteCommand_024(self): |
| 2775 |
""" |
| 2776 |
Execute a command that should succeed, two arguments, returnOutput=True |
| 2777 |
Do this all bundled into the command list, just to check that this works as expected. |
| 2778 |
Command-line: python -c "import sys; print(''); sys.exit(0)" |
| 2779 |
""" |
| 2780 |
command = [ |
| 2781 |
sys.executable, |
| 2782 |
"-c", |
| 2783 |
"import sys; print(''); sys.exit(0)", |
| 2784 |
] |
| 2785 |
args = [] |
| 2786 |
(result, output) = executeCommand(command, args, returnOutput=True) |
| 2787 |
self.assertEqual(0, result) |
| 2788 |
self.assertEqual(1, len(output)) |
| 2789 |
self.assertEqual(os.linesep, output[0]) |
| 2790 |
|
| 2791 |
def testExecuteCommand_025(self): |
| 2792 |
""" |
| 2793 |
Execute a command that should succeed, three arguments, returnOutput=True |
| 2794 |
Do this all bundled into the command list, just to check that this works as expected. |
| 2795 |
Command-line: python -c "import sys; print('%s' % (sys.argv[1])); sys.exit(0)" first |
| 2796 |
""" |
| 2797 |
command = [ |
| 2798 |
sys.executable, |
| 2799 |
"-c", |
| 2800 |
"import sys; print('%s' % (sys.argv[1])); sys.exit(0)", |
| 2801 |
"first", |
| 2802 |
] |
| 2803 |
args = [] |
| 2804 |
(result, output) = executeCommand(command, args, returnOutput=True) |
| 2805 |
self.assertEqual(0, result) |
| 2806 |
self.assertEqual(1, len(output)) |
| 2807 |
self.assertEqual("first%s" % os.linesep, output[0]) |
| 2808 |
|
| 2809 |
def testExecuteCommand_026(self): |
| 2810 |
""" |
| 2811 |
Execute a command that should succeed, four arguments, returnOutput=True |
| 2812 |
Do this all bundled into the command list, just to check that this works as expected. |
| 2813 |
Command-line: python -c "import sys; print('%s' % sys.argv[1]); print('%s' % sys.argv[2]); sys.exit(0)" first second |
| 2814 |
""" |
| 2815 |
command = [ |
| 2816 |
sys.executable, |
| 2817 |
"-c", |
| 2818 |
"import sys; print('%s' % sys.argv[1]); print('%s' % sys.argv[2]); sys.exit(0)", |
| 2819 |
"first", |
| 2820 |
"second", |
| 2821 |
] |
| 2822 |
args = [] |
| 2823 |
(result, output) = executeCommand(command, args, returnOutput=True) |
| 2824 |
self.assertEqual(0, result) |
| 2825 |
self.assertEqual(2, len(output)) |
| 2826 |
self.assertEqual("first%s" % os.linesep, output[0]) |
| 2827 |
self.assertEqual("second%s" % os.linesep, output[1]) |
| 2828 |
|
| 2829 |
def testExecuteCommand_027(self): |
| 2830 |
""" |
| 2831 |
Execute a command that should fail, returnOutput=True |
| 2832 |
Do this all bundled into the command list, just to check that this works as expected. |
| 2833 |
Command-line: python -c "import sys; print(''); sys.exit(1)" |
| 2834 |
""" |
| 2835 |
command = [ |
| 2836 |
sys.executable, |
| 2837 |
"-c", |
| 2838 |
"import sys; print(''); sys.exit(1)", |
| 2839 |
] |
| 2840 |
args = [] |
| 2841 |
(result, output) = executeCommand(command, args, returnOutput=True) |
| 2842 |
self.assertNotEqual(0, result) |
| 2843 |
self.assertEqual(1, len(output)) |
| 2844 |
self.assertEqual(os.linesep, output[0]) |
| 2845 |
|
| 2846 |
def testExecuteCommand_028(self): |
| 2847 |
""" |
| 2848 |
Execute a command that should fail, more arguments, returnOutput=True |
| 2849 |
Do this all bundled into the command list, just to check that this works as expected. |
| 2850 |
Command-line: python -c "import sys; print('%s' % sys.argv[1]); print('%s' % sys.argv[2]); sys.exit(1)" first second |
| 2851 |
""" |
| 2852 |
command = [ |
| 2853 |
sys.executable, |
| 2854 |
"-c", |
| 2855 |
"import sys; print('%s' % sys.argv[1]); print('%s' % sys.argv[2]); sys.exit(1)", |
| 2856 |
"first", |
| 2857 |
"second", |
| 2858 |
] |
| 2859 |
args = [] |
| 2860 |
(result, output) = executeCommand(command, args, returnOutput=True) |
| 2861 |
self.assertNotEqual(0, result) |
| 2862 |
self.assertEqual(2, len(output)) |
| 2863 |
self.assertEqual("first%s" % os.linesep, output[0]) |
| 2864 |
self.assertEqual("second%s" % os.linesep, output[1]) |
| 2865 |
|
| 2866 |
def testExecuteCommand_030(self): |
| 2867 |
""" |
| 2868 |
Execute a command that should succeed, no arguments, returnOutput=False, ignoring stderr. |
| 2869 |
Command-line: non-Python platform-specific valid command |
| 2870 |
""" |
| 2871 |
command = VALID_COMMAND |
| 2872 |
args = VALID_ARGS |
| 2873 |
(result, output) = executeCommand(command, args, returnOutput=False, ignoreStderr=True) |
| 2874 |
self.assertEqual(0, result) |
| 2875 |
self.assertEqual(None, output) |
| 2876 |
|
| 2877 |
def testExecuteCommand_031(self): |
| 2878 |
""" |
| 2879 |
Execute a command that should succeed, one argument, returnOutput=False, ignoring stderr. |
| 2880 |
Command-line: python -V |
| 2881 |
""" |
| 2882 |
command = [ |
| 2883 |
sys.executable, |
| 2884 |
] |
| 2885 |
args = [ |
| 2886 |
"-V", |
| 2887 |
] |
| 2888 |
(result, output) = executeCommand(command, args, returnOutput=False, ignoreStderr=True) |
| 2889 |
self.assertEqual(0, result) |
| 2890 |
self.assertEqual(None, output) |
| 2891 |
|
| 2892 |
def testExecuteCommand_032(self): |
| 2893 |
""" |
| 2894 |
Execute a command that should succeed, two arguments, returnOutput=False, ignoring stderr. |
| 2895 |
Command-line: python -c "import sys; print(sys.argv[1:]); sys.exit(0)" |
| 2896 |
""" |
| 2897 |
command = [ |
| 2898 |
sys.executable, |
| 2899 |
] |
| 2900 |
args = [ |
| 2901 |
"-c", |
| 2902 |
"import sys; print(sys.argv[1:]); sys.exit(0)", |
| 2903 |
] |
| 2904 |
(result, output) = executeCommand(command, args, returnOutput=False, ignoreStderr=True) |
| 2905 |
self.assertEqual(0, result) |
| 2906 |
self.assertEqual(None, output) |
| 2907 |
|
| 2908 |
def testExecuteCommand_033(self): |
| 2909 |
""" |
| 2910 |
Execute a command that should succeed, three arguments, returnOutput=False, ignoring stderr. |
| 2911 |
Command-line: python -c "import sys; print(sys.argv[1:]); sys.exit(0)" first |
| 2912 |
""" |
| 2913 |
command = [ |
| 2914 |
sys.executable, |
| 2915 |
] |
| 2916 |
args = [ |
| 2917 |
"-c", |
| 2918 |
"import sys; print(sys.argv[1:]); sys.exit(0)", |
| 2919 |
"first", |
| 2920 |
] |
| 2921 |
(result, output) = executeCommand(command, args, returnOutput=False, ignoreStderr=True) |
| 2922 |
self.assertEqual(0, result) |
| 2923 |
self.assertEqual(None, output) |
| 2924 |
|
| 2925 |
def testExecuteCommand_034(self): |
| 2926 |
""" |
| 2927 |
Execute a command that should succeed, four arguments, returnOutput=False, ignoring stderr. |
| 2928 |
Command-line: python -c "import sys; print(sys.argv[1:]); sys.exit(0)" first second |
| 2929 |
""" |
| 2930 |
command = [ |
| 2931 |
sys.executable, |
| 2932 |
] |
| 2933 |
args = [ |
| 2934 |
"-c", |
| 2935 |
"import sys; print(sys.argv[1:]); sys.exit(0)", |
| 2936 |
"first", |
| 2937 |
"second", |
| 2938 |
] |
| 2939 |
(result, output) = executeCommand(command, args, returnOutput=False, ignoreStderr=True) |
| 2940 |
self.assertEqual(0, result) |
| 2941 |
self.assertEqual(None, output) |
| 2942 |
|
| 2943 |
def testExecuteCommand_035(self): |
| 2944 |
""" |
| 2945 |
Execute a command that should fail, returnOutput=False, ignoring stderr. |
| 2946 |
Command-line: python -c "import sys; print(sys.argv[1:]); sys.exit(1)" |
| 2947 |
""" |
| 2948 |
command = [ |
| 2949 |
sys.executable, |
| 2950 |
] |
| 2951 |
args = [ |
| 2952 |
"-c", |
| 2953 |
"import sys; print(sys.argv[1:]); sys.exit(1)", |
| 2954 |
] |
| 2955 |
(result, output) = executeCommand(command, args, returnOutput=False, ignoreStderr=True) |
| 2956 |
self.assertNotEqual(0, result) |
| 2957 |
self.assertEqual(None, output) |
| 2958 |
|
| 2959 |
def testExecuteCommand_036(self): |
| 2960 |
""" |
| 2961 |
Execute a command that should fail, more arguments, returnOutput=False, ignoring stderr. |
| 2962 |
Command-line: python -c "import sys; print(sys.argv[1:]); sys.exit(1)" first second |
| 2963 |
""" |
| 2964 |
command = [ |
| 2965 |
sys.executable, |
| 2966 |
] |
| 2967 |
args = [ |
| 2968 |
"-c", |
| 2969 |
"import sys; print(sys.argv[1:]); sys.exit(1)", |
| 2970 |
"first", |
| 2971 |
"second", |
| 2972 |
] |
| 2973 |
(result, output) = executeCommand(command, args, returnOutput=False, ignoreStderr=True) |
| 2974 |
self.assertNotEqual(0, result) |
| 2975 |
self.assertEqual(None, output) |
| 2976 |
|
| 2977 |
def testExecuteCommand_037(self): |
| 2978 |
""" |
| 2979 |
Execute a command that should succeed, no arguments, returnOutput=True, ignoring stderr. |
| 2980 |
Command-line: non-Python platform-specific valid command |
| 2981 |
""" |
| 2982 |
command = VALID_COMMAND |
| 2983 |
args = VALID_ARGS |
| 2984 |
(result, output) = executeCommand(command, args, returnOutput=True, ignoreStderr=True) |
| 2985 |
self.assertEqual(0, result) |
| 2986 |
self.assertEqual(1, len(output)) |
| 2987 |
self.assertEqual(VALID_OUTPUT, output[0]) |
| 2988 |
|
| 2989 |
def testExecuteCommand_038(self): |
| 2990 |
""" |
| 2991 |
Execute a command that should succeed, one argument, returnOutput=True, ignoring stderr. |
| 2992 |
Command-line: python -V |
| 2993 |
""" |
| 2994 |
command = [ |
| 2995 |
sys.executable, |
| 2996 |
] |
| 2997 |
args = [ |
| 2998 |
"-c", |
| 2999 |
"import sys; print('X', file=sys.stderr)", |
| 3000 |
] |
| 3001 |
(result, output) = executeCommand(command, args, returnOutput=True, ignoreStderr=False) |
| 3002 |
self.assertEqual(0, result) |
| 3003 |
self.assertEqual(1, len(output)) |
| 3004 |
self.assertEqual("X%s" % os.linesep, output[0]) # prove stderr is captured |
| 3005 |
(result, output) = executeCommand(command, args, returnOutput=True, ignoreStderr=True) |
| 3006 |
self.assertEqual(0, result) |
| 3007 |
self.assertEqual(0, len(output)) # prove stderr is now ignored |
| 3008 |
|
| 3009 |
def testExecuteCommand_039(self): |
| 3010 |
""" |
| 3011 |
Execute a command that should succeed, two arguments, returnOutput=True, ignoring stderr. |
| 3012 |
Command-line: python -c "import sys; print(''); sys.exit(0)" |
| 3013 |
""" |
| 3014 |
command = [ |
| 3015 |
sys.executable, |
| 3016 |
] |
| 3017 |
args = [ |
| 3018 |
"-c", |
| 3019 |
"import sys; print(''); sys.exit(0)", |
| 3020 |
] |
| 3021 |
(result, output) = executeCommand(command, args, returnOutput=True, ignoreStderr=True) |
| 3022 |
self.assertEqual(0, result) |
| 3023 |
self.assertEqual(1, len(output)) |
| 3024 |
self.assertEqual(os.linesep, output[0]) |
| 3025 |
|
| 3026 |
def testExecuteCommand_040(self): |
| 3027 |
""" |
| 3028 |
Execute a command that should succeed, three arguments, returnOutput=True, ignoring stderr. |
| 3029 |
Command-line: python -c "import sys; print('%s' % (sys.argv[1])); sys.exit(0)" first |
| 3030 |
""" |
| 3031 |
command = [ |
| 3032 |
sys.executable, |
| 3033 |
] |
| 3034 |
args = [ |
| 3035 |
"-c", |
| 3036 |
"import sys; print('%s' % (sys.argv[1])); sys.exit(0)", |
| 3037 |
"first", |
| 3038 |
] |
| 3039 |
(result, output) = executeCommand(command, args, returnOutput=True, ignoreStderr=True) |
| 3040 |
self.assertEqual(0, result) |
| 3041 |
self.assertEqual(1, len(output)) |
| 3042 |
self.assertEqual("first%s" % os.linesep, output[0]) |
| 3043 |
|
| 3044 |
def testExecuteCommand_041(self): |
| 3045 |
""" |
| 3046 |
Execute a command that should succeed, four arguments, returnOutput=True, ignoring stderr. |
| 3047 |
Command-line: python -c "import sys; print('%s' % sys.argv[1]); print('%s' % sys.argv[2]); sys.exit(0)" first second |
| 3048 |
""" |
| 3049 |
command = [ |
| 3050 |
sys.executable, |
| 3051 |
] |
| 3052 |
args = [ |
| 3053 |
"-c", |
| 3054 |
"import sys; print('%s' % sys.argv[1]); print('%s' % sys.argv[2]); sys.exit(0)", |
| 3055 |
"first", |
| 3056 |
"second", |
| 3057 |
] |
| 3058 |
(result, output) = executeCommand(command, args, returnOutput=True, ignoreStderr=True) |
| 3059 |
self.assertEqual(0, result) |
| 3060 |
self.assertEqual(2, len(output)) |
| 3061 |
self.assertEqual("first%s" % os.linesep, output[0]) |
| 3062 |
self.assertEqual("second%s" % os.linesep, output[1]) |
| 3063 |
|
| 3064 |
def testExecuteCommand_042(self): |
| 3065 |
""" |
| 3066 |
Execute a command that should fail, returnOutput=True, ignoring stderr. |
| 3067 |
Command-line: python -c "import sys; print(''); sys.exit(1)" |
| 3068 |
""" |
| 3069 |
command = [ |
| 3070 |
sys.executable, |
| 3071 |
] |
| 3072 |
args = [ |
| 3073 |
"-c", |
| 3074 |
"import sys; print(''); sys.exit(1)", |
| 3075 |
] |
| 3076 |
(result, output) = executeCommand(command, args, returnOutput=True, ignoreStderr=True) |
| 3077 |
self.assertNotEqual(0, result) |
| 3078 |
self.assertEqual(1, len(output)) |
| 3079 |
self.assertEqual(os.linesep, output[0]) |
| 3080 |
|
| 3081 |
def testExecuteCommand_043(self): |
| 3082 |
""" |
| 3083 |
Execute a command that should fail, more arguments, returnOutput=True, ignoring stderr. |
| 3084 |
Command-line: python -c "import sys; print('%s' % sys.argv[1]); print('%s' % sys.argv[2]); sys.exit(1)" first second |
| 3085 |
""" |
| 3086 |
command = [ |
| 3087 |
sys.executable, |
| 3088 |
] |
| 3089 |
args = [ |
| 3090 |
"-c", |
| 3091 |
"import sys; print('%s' % sys.argv[1]); print('%s' % sys.argv[2]); sys.exit(1)", |
| 3092 |
"first", |
| 3093 |
"second", |
| 3094 |
] |
| 3095 |
(result, output) = executeCommand(command, args, returnOutput=True, ignoreStderr=True) |
| 3096 |
self.assertNotEqual(0, result) |
| 3097 |
self.assertEqual(2, len(output)) |
| 3098 |
self.assertEqual("first%s" % os.linesep, output[0]) |
| 3099 |
self.assertEqual("second%s" % os.linesep, output[1]) |
| 3100 |
|
| 3101 |
def testExecuteCommand_044(self): |
| 3102 |
""" |
| 3103 |
Execute a command that should succeed, no arguments, returnOutput=False, ignoring stderr. |
| 3104 |
Do this all bundled into the command list, just to check that this works as expected. |
| 3105 |
Command-line: non-Python platform-specific valid command |
| 3106 |
""" |
| 3107 |
command = VALID_COMMAND |
| 3108 |
args = VALID_ARGS |
| 3109 |
(result, output) = executeCommand(command, args, returnOutput=False, ignoreStderr=True) |
| 3110 |
self.assertEqual(0, result) |
| 3111 |
self.assertEqual(None, output) |
| 3112 |
|
| 3113 |
def testExecuteCommand_045(self): |
| 3114 |
""" |
| 3115 |
Execute a command that should succeed, one argument, returnOutput=False, ignoring stderr. |
| 3116 |
Do this all bundled into the command list, just to check that this works as expected. |
| 3117 |
Command-line: python -V |
| 3118 |
""" |
| 3119 |
command = [ |
| 3120 |
sys.executable, |
| 3121 |
"-V", |
| 3122 |
] |
| 3123 |
args = [] |
| 3124 |
(result, output) = executeCommand(command, args, returnOutput=False, ignoreStderr=True) |
| 3125 |
self.assertEqual(0, result) |
| 3126 |
self.assertEqual(None, output) |
| 3127 |
|
| 3128 |
def testExecuteCommand_046(self): |
| 3129 |
""" |
| 3130 |
Execute a command that should succeed, two arguments, returnOutput=False, ignoring stderr. |
| 3131 |
Do this all bundled into the command list, just to check that this works as expected. |
| 3132 |
Command-line: python -c "import sys; print(sys.argv[1:]); sys.exit(0)" |
| 3133 |
""" |
| 3134 |
command = [ |
| 3135 |
sys.executable, |
| 3136 |
"-c", |
| 3137 |
"import sys; print(sys.argv[1:]); sys.exit(0)", |
| 3138 |
] |
| 3139 |
args = [] |
| 3140 |
(result, output) = executeCommand(command, args, returnOutput=False, ignoreStderr=True) |
| 3141 |
self.assertEqual(0, result) |
| 3142 |
self.assertEqual(None, output) |
| 3143 |
|
| 3144 |
def testExecuteCommand_047(self): |
| 3145 |
""" |
| 3146 |
Execute a command that should succeed, three arguments, returnOutput=False, ignoring stderr. |
| 3147 |
Do this all bundled into the command list, just to check that this works as expected. |
| 3148 |
Command-line: python -c "import sys; print(sys.argv[1:]); sys.exit(0)" first |
| 3149 |
""" |
| 3150 |
command = [ |
| 3151 |
sys.executable, |
| 3152 |
"-c", |
| 3153 |
"import sys; print(sys.argv[1:]); sys.exit(0)", |
| 3154 |
"first", |
| 3155 |
] |
| 3156 |
args = [] |
| 3157 |
(result, output) = executeCommand(command, args, returnOutput=False, ignoreStderr=True) |
| 3158 |
self.assertEqual(0, result) |
| 3159 |
self.assertEqual(None, output) |
| 3160 |
|
| 3161 |
def testExecuteCommand_048(self): |
| 3162 |
""" |
| 3163 |
Execute a command that should succeed, four arguments, returnOutput=False, ignoring stderr. |
| 3164 |
Do this all bundled into the command list, just to check that this works as expected. |
| 3165 |
Command-line: python -c "import sys; print(sys.argv[1:]); sys.exit(0)" first second |
| 3166 |
""" |
| 3167 |
command = [ |
| 3168 |
sys.executable, |
| 3169 |
"-c", |
| 3170 |
"import sys; print(sys.argv[1:]); sys.exit(0)", |
| 3171 |
"first", |
| 3172 |
"second", |
| 3173 |
] |
| 3174 |
args = [] |
| 3175 |
(result, output) = executeCommand(command, args, returnOutput=False, ignoreStderr=True) |
| 3176 |
self.assertEqual(0, result) |
| 3177 |
self.assertEqual(None, output) |
| 3178 |
|
| 3179 |
def testExecuteCommand_049(self): |
| 3180 |
""" |
| 3181 |
Execute a command that should fail, returnOutput=False, ignoring stderr. |
| 3182 |
Do this all bundled into the command list, just to check that this works as expected. |
| 3183 |
Command-line: python -c "import sys; print(sys.argv[1:]); sys.exit(1)" |
| 3184 |
""" |
| 3185 |
command = [ |
| 3186 |
sys.executable, |
| 3187 |
"-c", |
| 3188 |
"import sys; print(sys.argv[1:]); sys.exit(1)", |
| 3189 |
] |
| 3190 |
args = [] |
| 3191 |
(result, output) = executeCommand(command, args, returnOutput=False, ignoreStderr=True) |
| 3192 |
self.assertNotEqual(0, result) |
| 3193 |
self.assertEqual(None, output) |
| 3194 |
|
| 3195 |
def testExecuteCommand_050(self): |
| 3196 |
""" |
| 3197 |
Execute a command that should fail, more arguments, returnOutput=False, ignoring stderr. |
| 3198 |
Do this all bundled into the command list, just to check that this works as expected. |
| 3199 |
Command-line: python -c "import sys; print(sys.argv[1:]); sys.exit(1)" first second |
| 3200 |
""" |
| 3201 |
command = [ |
| 3202 |
sys.executable, |
| 3203 |
"-c", |
| 3204 |
"import sys; print(sys.argv[1:]); sys.exit(1)", |
| 3205 |
"first", |
| 3206 |
"second", |
| 3207 |
] |
| 3208 |
args = [] |
| 3209 |
(result, output) = executeCommand(command, args, returnOutput=False, ignoreStderr=True) |
| 3210 |
self.assertNotEqual(0, result) |
| 3211 |
self.assertEqual(None, output) |
| 3212 |
|
| 3213 |
def testExecuteCommand_051(self): |
| 3214 |
""" |
| 3215 |
Execute a command that should succeed, no arguments, returnOutput=True, ignoring stderr. |
| 3216 |
Do this all bundled into the command list, just to check that this works as expected. |
| 3217 |
Command-line: non-Python platform-specific valid command |
| 3218 |
""" |
| 3219 |
command = VALID_COMMAND |
| 3220 |
args = VALID_ARGS |
| 3221 |
(result, output) = executeCommand(command, args, returnOutput=True, ignoreStderr=True) |
| 3222 |
self.assertEqual(0, result) |
| 3223 |
self.assertEqual(1, len(output)) |
| 3224 |
self.assertEqual(VALID_OUTPUT, output[0]) |
| 3225 |
|
| 3226 |
def testExecuteCommand_052(self): |
| 3227 |
""" |
| 3228 |
Execute a command that should succeed, one argument, returnOutput=True, ignoring stderr. |
| 3229 |
Do this all bundled into the command list, just to check that this works as expected. |
| 3230 |
Command-line: python -V |
| 3231 |
""" |
| 3232 |
command = [ |
| 3233 |
sys.executable, |
| 3234 |
"-c", |
| 3235 |
"import sys; print('X', file=sys.stderr)", |
| 3236 |
] |
| 3237 |
args = [] |
| 3238 |
(result, output) = executeCommand(command, args, returnOutput=True, ignoreStderr=False) |
| 3239 |
self.assertEqual(0, result) |
| 3240 |
self.assertEqual(1, len(output)) |
| 3241 |
self.assertEqual("X%s" % os.linesep, output[0]) # prove stderr is captured |
| 3242 |
(result, output) = executeCommand(command, args, returnOutput=True, ignoreStderr=True) |
| 3243 |
self.assertEqual(0, result) |
| 3244 |
self.assertEqual(0, len(output)) # prove stderr is now ignored |
| 3245 |
|
| 3246 |
def testExecuteCommand_053(self): |
| 3247 |
""" |
| 3248 |
Execute a command that should succeed, two arguments, returnOutput=True, ignoring stderr. |
| 3249 |
Do this all bundled into the command list, just to check that this works as expected. |
| 3250 |
Command-line: python -c "import sys; print(''); sys.exit(0)" |
| 3251 |
""" |
| 3252 |
command = [ |
| 3253 |
sys.executable, |
| 3254 |
"-c", |
| 3255 |
"import sys; print(''); sys.exit(0)", |
| 3256 |
] |
| 3257 |
args = [] |
| 3258 |
(result, output) = executeCommand(command, args, returnOutput=True, ignoreStderr=True) |
| 3259 |
self.assertEqual(0, result) |
| 3260 |
self.assertEqual(1, len(output)) |
| 3261 |
self.assertEqual(os.linesep, output[0]) |
| 3262 |
|
| 3263 |
def testExecuteCommand_054(self): |
| 3264 |
""" |
| 3265 |
Execute a command that should succeed, three arguments, returnOutput=True, ignoring stderr. |
| 3266 |
Do this all bundled into the command list, just to check that this works as expected. |
| 3267 |
Command-line: python -c "import sys; print('%s' % (sys.argv[1])); sys.exit(0)" first |
| 3268 |
""" |
| 3269 |
command = [ |
| 3270 |
sys.executable, |
| 3271 |
"-c", |
| 3272 |
"import sys; print('%s' % (sys.argv[1])); sys.exit(0)", |
| 3273 |
"first", |
| 3274 |
] |
| 3275 |
args = [] |
| 3276 |
(result, output) = executeCommand(command, args, returnOutput=True, ignoreStderr=True) |
| 3277 |
self.assertEqual(0, result) |
| 3278 |
self.assertEqual(1, len(output)) |
| 3279 |
self.assertEqual("first%s" % os.linesep, output[0]) |
| 3280 |
|
| 3281 |
def testExecuteCommand_055(self): |
| 3282 |
""" |
| 3283 |
Execute a command that should succeed, four arguments, returnOutput=True, ignoring stderr. |
| 3284 |
Do this all bundled into the command list, just to check that this works as expected. |
| 3285 |
Command-line: python -c "import sys; print('%s' % sys.argv[1]); print('%s' % sys.argv[2]); sys.exit(0)" first second |
| 3286 |
""" |
| 3287 |
command = [ |
| 3288 |
sys.executable, |
| 3289 |
"-c", |
| 3290 |
"import sys; print('%s' % sys.argv[1]); print('%s' % sys.argv[2]); sys.exit(0)", |
| 3291 |
"first", |
| 3292 |
"second", |
| 3293 |
] |
| 3294 |
args = [] |
| 3295 |
(result, output) = executeCommand(command, args, returnOutput=True, ignoreStderr=True) |
| 3296 |
self.assertEqual(0, result) |
| 3297 |
self.assertEqual(2, len(output)) |
| 3298 |
self.assertEqual("first%s" % os.linesep, output[0]) |
| 3299 |
self.assertEqual("second%s" % os.linesep, output[1]) |
| 3300 |
|
| 3301 |
def testExecuteCommand_056(self): |
| 3302 |
""" |
| 3303 |
Execute a command that should fail, returnOutput=True, ignoring stderr. |
| 3304 |
Do this all bundled into the command list, just to check that this works as expected. |
| 3305 |
Command-line: python -c "import sys; print(''); sys.exit(1)" |
| 3306 |
""" |
| 3307 |
command = [ |
| 3308 |
sys.executable, |
| 3309 |
"-c", |
| 3310 |
"import sys; print(''); sys.exit(1)", |
| 3311 |
] |
| 3312 |
args = [] |
| 3313 |
(result, output) = executeCommand(command, args, returnOutput=True, ignoreStderr=True) |
| 3314 |
self.assertNotEqual(0, result) |
| 3315 |
self.assertEqual(1, len(output)) |
| 3316 |
self.assertEqual(os.linesep, output[0]) |
| 3317 |
|
| 3318 |
def testExecuteCommand_057(self): |
| 3319 |
""" |
| 3320 |
Execute a command that should fail, more arguments, returnOutput=True, ignoring stderr. |
| 3321 |
Do this all bundled into the command list, just to check that this works as expected. |
| 3322 |
Command-line: python -c "import sys; print('%s' % sys.argv[1]); print('%s' % sys.argv[2]); sys.exit(1)" first second |
| 3323 |
""" |
| 3324 |
command = [ |
| 3325 |
sys.executable, |
| 3326 |
"-c", |
| 3327 |
"import sys; print('%s' % sys.argv[1]); print('%s' % sys.argv[2]); sys.exit(1)", |
| 3328 |
"first", |
| 3329 |
"second", |
| 3330 |
] |
| 3331 |
args = [] |
| 3332 |
(result, output) = executeCommand(command, args, returnOutput=True, ignoreStderr=True) |
| 3333 |
self.assertNotEqual(0, result) |
| 3334 |
self.assertEqual(2, len(output)) |
| 3335 |
self.assertEqual("first%s" % os.linesep, output[0]) |
| 3336 |
self.assertEqual("second%s" % os.linesep, output[1]) |
| 3337 |
|
| 3338 |
def testExecuteCommand_058(self): |
| 3339 |
""" |
| 3340 |
Execute a command that should succeed, no arguments, returnOutput=False, using outputFile. |
| 3341 |
Do this all bundled into the command list, just to check that this works as expected. |
| 3342 |
Command-line: non-Python platform-specific valid command |
| 3343 |
""" |
| 3344 |
command = VALID_COMMAND |
| 3345 |
args = VALID_ARGS |
| 3346 |
|
| 3347 |
filename = self.getTempfile() |
| 3348 |
with open(filename, "wb") as outputFile: |
| 3349 |
result = executeCommand(command, args, returnOutput=False, outputFile=outputFile)[0] |
| 3350 |
self.assertEqual(0, result) |
| 3351 |
self.assertTrue(os.path.exists(filename)) |
| 3352 |
with open(filename) as f: |
| 3353 |
output = f.readlines() |
| 3354 |
|
| 3355 |
self.assertEqual(1, len(output)) |
| 3356 |
self.assertEqual( |
| 3357 |
VALID_OUTPUT, output[0].replace("\n", os.linesep) |
| 3358 |
) # when reading from a file, Python translates the line ending |
| 3359 |
|
| 3360 |
def testExecuteCommand_059(self): |
| 3361 |
""" |
| 3362 |
Execute a command that should succeed, one argument, returnOutput=False, using outputFile. |
| 3363 |
Do this all bundled into the command list, just to check that this works as expected. |
| 3364 |
Command-line: python -V |
| 3365 |
""" |
| 3366 |
command = [sys.executable, "-V"] |
| 3367 |
args = [] |
| 3368 |
|
| 3369 |
filename = self.getTempfile() |
| 3370 |
with open(filename, "wb") as outputFile: |
| 3371 |
result = executeCommand(command, args, returnOutput=False, outputFile=outputFile)[0] |
| 3372 |
self.assertEqual(0, result) |
| 3373 |
self.assertTrue(os.path.exists(filename)) |
| 3374 |
with open(filename) as f: |
| 3375 |
output = f.readlines() |
| 3376 |
|
| 3377 |
self.assertEqual(1, len(output)) |
| 3378 |
self.assertTrue(output[0].startswith("Python")) |
| 3379 |
|
| 3380 |
def testExecuteCommand_060(self): |
| 3381 |
""" |
| 3382 |
Execute a command that should succeed, two arguments, returnOutput=False, using outputFile. |
| 3383 |
Do this all bundled into the command list, just to check that this works as expected. |
| 3384 |
Command-line: python -c "import sys; print(''); sys.exit(0)" |
| 3385 |
""" |
| 3386 |
command = [ |
| 3387 |
sys.executable, |
| 3388 |
"-c", |
| 3389 |
"import sys; print(''); sys.exit(0)", |
| 3390 |
] |
| 3391 |
args = [] |
| 3392 |
|
| 3393 |
filename = self.getTempfile() |
| 3394 |
with open(filename, "wb") as outputFile: |
| 3395 |
result = executeCommand(command, args, returnOutput=False, outputFile=outputFile)[0] |
| 3396 |
self.assertEqual(0, result) |
| 3397 |
self.assertTrue(os.path.exists(filename)) |
| 3398 |
with open(filename) as f: |
| 3399 |
output = f.readlines() |
| 3400 |
|
| 3401 |
self.assertEqual(1, len(output)) |
| 3402 |
self.assertEqual("\n", output[0]) |
| 3403 |
|
| 3404 |
def testExecuteCommand_061(self): |
| 3405 |
""" |
| 3406 |
Execute a command that should succeed, three arguments, returnOutput=False, using outputFile. |
| 3407 |
Do this all bundled into the command list, just to check that this works as expected. |
| 3408 |
Command-line: python -c "import sys; print('%s' % (sys.argv[1])); sys.exit(0)" first |
| 3409 |
""" |
| 3410 |
command = [ |
| 3411 |
sys.executable, |
| 3412 |
"-c", |
| 3413 |
"import sys; print('%s' % (sys.argv[1])); sys.exit(0)", |
| 3414 |
"first", |
| 3415 |
] |
| 3416 |
args = [] |
| 3417 |
|
| 3418 |
filename = self.getTempfile() |
| 3419 |
with open(filename, "wb") as outputFile: |
| 3420 |
result = executeCommand(command, args, returnOutput=False, outputFile=outputFile)[0] |
| 3421 |
self.assertEqual(0, result) |
| 3422 |
self.assertTrue(os.path.exists(filename)) |
| 3423 |
with open(filename) as f: |
| 3424 |
output = f.readlines() |
| 3425 |
|
| 3426 |
self.assertEqual(1, len(output)) |
| 3427 |
self.assertEqual("first\n", output[0]) |
| 3428 |
|
| 3429 |
def testExecuteCommand_062(self): |
| 3430 |
""" |
| 3431 |
Execute a command that should succeed, four arguments, returnOutput=False, using outputFile. |
| 3432 |
Do this all bundled into the command list, just to check that this works as expected. |
| 3433 |
Command-line: python -c "import sys; print('%s' % sys.argv[1]); print('%s' % sys.argv[2]); sys.exit(0)" first second |
| 3434 |
""" |
| 3435 |
command = [ |
| 3436 |
sys.executable, |
| 3437 |
"-c", |
| 3438 |
"import sys; print('%s' % sys.argv[1]); print('%s' % sys.argv[2]); sys.exit(0)", |
| 3439 |
"first", |
| 3440 |
"second", |
| 3441 |
] |
| 3442 |
args = [] |
| 3443 |
|
| 3444 |
filename = self.getTempfile() |
| 3445 |
with open(filename, "wb") as outputFile: |
| 3446 |
result = executeCommand(command, args, returnOutput=False, outputFile=outputFile)[0] |
| 3447 |
self.assertEqual(0, result) |
| 3448 |
self.assertTrue(os.path.exists(filename)) |
| 3449 |
with open(filename) as f: |
| 3450 |
output = f.readlines() |
| 3451 |
|
| 3452 |
self.assertEqual(2, len(output)) |
| 3453 |
self.assertEqual("first\n", output[0]) |
| 3454 |
self.assertEqual("second\n", output[1]) |
| 3455 |
|
| 3456 |
def testExecuteCommand_063(self): |
| 3457 |
""" |
| 3458 |
Execute a command that should fail, returnOutput=False, using outputFile. |
| 3459 |
Do this all bundled into the command list, just to check that this works as expected. |
| 3460 |
Command-line: python -c "import sys; print(''); sys.exit(1)" |
| 3461 |
""" |
| 3462 |
command = [ |
| 3463 |
sys.executable, |
| 3464 |
"-c", |
| 3465 |
"import sys; print(''); sys.exit(1)", |
| 3466 |
] |
| 3467 |
args = [] |
| 3468 |
|
| 3469 |
filename = self.getTempfile() |
| 3470 |
with open(filename, "wb") as outputFile: |
| 3471 |
result = executeCommand(command, args, returnOutput=False, outputFile=outputFile)[0] |
| 3472 |
self.assertNotEqual(0, result) |
| 3473 |
self.assertTrue(os.path.exists(filename)) |
| 3474 |
with open(filename) as f: |
| 3475 |
output = f.readlines() |
| 3476 |
|
| 3477 |
self.assertEqual(1, len(output)) |
| 3478 |
self.assertEqual("\n", output[0]) |
| 3479 |
|
| 3480 |
def testExecuteCommand_064(self): |
| 3481 |
""" |
| 3482 |
Execute a command that should fail, more arguments, returnOutput=False, using outputFile. |
| 3483 |
Do this all bundled into the command list, just to check that this works as expected. |
| 3484 |
Command-line: python -c "import sys; print('%s' % sys.argv[1]); print('%s' % sys.argv[2]); sys.exit(1)" first second |
| 3485 |
""" |
| 3486 |
command = [ |
| 3487 |
sys.executable, |
| 3488 |
"-c", |
| 3489 |
"import sys; print('%s' % sys.argv[1]); print('%s' % sys.argv[2]); sys.exit(1)", |
| 3490 |
"first", |
| 3491 |
"second", |
| 3492 |
] |
| 3493 |
args = [] |
| 3494 |
|
| 3495 |
filename = self.getTempfile() |
| 3496 |
with open(filename, "wb") as outputFile: |
| 3497 |
result = executeCommand(command, args, returnOutput=False, outputFile=outputFile)[0] |
| 3498 |
self.assertNotEqual(0, result) |
| 3499 |
self.assertTrue(os.path.exists(filename)) |
| 3500 |
with open(filename) as f: |
| 3501 |
output = f.readlines() |
| 3502 |
|
| 3503 |
self.assertEqual(2, len(output)) |
| 3504 |
self.assertEqual("first\n", output[0]) |
| 3505 |
self.assertEqual("second\n", output[1]) |
| 3506 |
|
| 3507 |
def testExecuteCommand_065(self): |
| 3508 |
""" |
| 3509 |
Execute a command with a huge amount of output all on stdout. The output |
| 3510 |
should contain only data on stdout, and ignoreStderr should be True. |
| 3511 |
This test helps confirm that the function doesn't hang when there is |
| 3512 |
either a lot of data or a lot of data to ignore. |
| 3513 |
""" |
| 3514 |
lotsoflines = self.resources["lotsoflines.py"] |
| 3515 |
command = [ |
| 3516 |
sys.executable, |
| 3517 |
lotsoflines, |
| 3518 |
"stdout", |
| 3519 |
] |
| 3520 |
args = [] |
| 3521 |
|
| 3522 |
filename = self.getTempfile() |
| 3523 |
with open(filename, "wb") as outputFile: |
| 3524 |
result = executeCommand(command, args, ignoreStderr=True, returnOutput=False, outputFile=outputFile)[0] |
| 3525 |
self.assertEqual(0, result) |
| 3526 |
|
| 3527 |
length = 0 |
| 3528 |
with open(filename) as contents: |
| 3529 |
for _i in contents: |
| 3530 |
length += 1 |
| 3531 |
|
| 3532 |
self.assertEqual(100000, length) |
| 3533 |
|
| 3534 |
def testExecuteCommand_066(self): |
| 3535 |
""" |
| 3536 |
Execute a command with a huge amount of output all on stdout. The output |
| 3537 |
should contain only data on stdout, and ignoreStderr should be False. |
| 3538 |
This test helps confirm that the function doesn't hang when there is |
| 3539 |
either a lot of data or a lot of data to ignore. |
| 3540 |
""" |
| 3541 |
lotsoflines = self.resources["lotsoflines.py"] |
| 3542 |
command = [ |
| 3543 |
sys.executable, |
| 3544 |
lotsoflines, |
| 3545 |
"stdout", |
| 3546 |
] |
| 3547 |
args = [] |
| 3548 |
|
| 3549 |
filename = self.getTempfile() |
| 3550 |
with open(filename, "wb") as outputFile: |
| 3551 |
result = executeCommand(command, args, ignoreStderr=False, returnOutput=False, outputFile=outputFile)[0] |
| 3552 |
self.assertEqual(0, result) |
| 3553 |
|
| 3554 |
length = 0 |
| 3555 |
with open(filename) as contents: |
| 3556 |
for _i in contents: |
| 3557 |
length += 1 |
| 3558 |
|
| 3559 |
self.assertEqual(100000, length) |
| 3560 |
|
| 3561 |
def testExecuteCommand_067(self): |
| 3562 |
""" |
| 3563 |
Execute a command with a huge amount of output all on stdout. The output |
| 3564 |
should contain only data on stderr, and ignoreStderr should be True. |
| 3565 |
This test helps confirm that the function doesn't hang when there is |
| 3566 |
either a lot of data or a lot of data to ignore. |
| 3567 |
""" |
| 3568 |
lotsoflines = self.resources["lotsoflines.py"] |
| 3569 |
command = [ |
| 3570 |
sys.executable, |
| 3571 |
lotsoflines, |
| 3572 |
"stderr", |
| 3573 |
] |
| 3574 |
args = [] |
| 3575 |
|
| 3576 |
filename = self.getTempfile() |
| 3577 |
with open(filename, "wb") as outputFile: |
| 3578 |
result = executeCommand(command, args, ignoreStderr=True, returnOutput=False, outputFile=outputFile)[0] |
| 3579 |
self.assertEqual(0, result) |
| 3580 |
|
| 3581 |
length = 0 |
| 3582 |
with open(filename) as contents: |
| 3583 |
for _i in contents: |
| 3584 |
length += 1 |
| 3585 |
|
| 3586 |
self.assertEqual(0, length) |
| 3587 |
|
| 3588 |
def testExecuteCommand_068(self): |
| 3589 |
""" |
| 3590 |
Execute a command with a huge amount of output all on stdout. The output |
| 3591 |
should contain only data on stdout, and ignoreStderr should be False. |
| 3592 |
This test helps confirm that the function doesn't hang when there is |
| 3593 |
either a lot of data or a lot of data to ignore. |
| 3594 |
""" |
| 3595 |
lotsoflines = self.resources["lotsoflines.py"] |
| 3596 |
command = [ |
| 3597 |
sys.executable, |
| 3598 |
lotsoflines, |
| 3599 |
"stderr", |
| 3600 |
] |
| 3601 |
args = [] |
| 3602 |
|
| 3603 |
filename = self.getTempfile() |
| 3604 |
with open(filename, "wb") as outputFile: |
| 3605 |
result = executeCommand(command, args, ignoreStderr=False, returnOutput=False, outputFile=outputFile)[0] |
| 3606 |
self.assertEqual(0, result) |
| 3607 |
|
| 3608 |
length = 0 |
| 3609 |
with open(filename) as contents: |
| 3610 |
for _i in contents: |
| 3611 |
length += 1 |
| 3612 |
|
| 3613 |
self.assertEqual(100000, length) |
| 3614 |
|
| 3615 |
def testExecuteCommand_069(self): |
| 3616 |
""" |
| 3617 |
Execute a command with a huge amount of output all on stdout. The output |
| 3618 |
should contain data on stdout and stderr, and ignoreStderr should be |
| 3619 |
True. This test helps confirm that the function doesn't hang when there |
| 3620 |
is either a lot of data or a lot of data to ignore. |
| 3621 |
""" |
| 3622 |
lotsoflines = self.resources["lotsoflines.py"] |
| 3623 |
command = [ |
| 3624 |
sys.executable, |
| 3625 |
lotsoflines, |
| 3626 |
"both", |
| 3627 |
] |
| 3628 |
args = [] |
| 3629 |
|
| 3630 |
filename = self.getTempfile() |
| 3631 |
with open(filename, "wb") as outputFile: |
| 3632 |
result = executeCommand(command, args, ignoreStderr=True, returnOutput=False, outputFile=outputFile)[0] |
| 3633 |
self.assertEqual(0, result) |
| 3634 |
|
| 3635 |
length = 0 |
| 3636 |
with open(filename) as contents: |
| 3637 |
for _i in contents: |
| 3638 |
length += 1 |
| 3639 |
|
| 3640 |
self.assertEqual(100000, length) |
| 3641 |
|
| 3642 |
def testExecuteCommand_070(self): |
| 3643 |
""" |
| 3644 |
Execute a command with a huge amount of output all on stdout. The output |
| 3645 |
should contain data on stdout and stderr, and ignoreStderr should be |
| 3646 |
False. This test helps confirm that the function doesn't hang when there |
| 3647 |
is either a lot of data or a lot of data to ignore. |
| 3648 |
""" |
| 3649 |
lotsoflines = self.resources["lotsoflines.py"] |
| 3650 |
command = [ |
| 3651 |
sys.executable, |
| 3652 |
lotsoflines, |
| 3653 |
"both", |
| 3654 |
] |
| 3655 |
args = [] |
| 3656 |
|
| 3657 |
filename = self.getTempfile() |
| 3658 |
with open(filename, "wb") as outputFile: |
| 3659 |
result = executeCommand(command, args, ignoreStderr=False, returnOutput=False, outputFile=outputFile)[0] |
| 3660 |
self.assertEqual(0, result) |
| 3661 |
|
| 3662 |
length = 0 |
| 3663 |
with open(filename) as contents: |
| 3664 |
for _i in contents: |
| 3665 |
length += 1 |
| 3666 |
|
| 3667 |
self.assertEqual(100000 * 2, length) |
| 3668 |
|
| 3669 |
#################### |
| 3670 |
# Test encodePath() |
| 3671 |
#################### |
| 3672 |
|
| 3673 |
def testEncodePath_002(self): |
| 3674 |
""" |
| 3675 |
Test with a simple string, empty. |
| 3676 |
""" |
| 3677 |
path = "" |
| 3678 |
safePath = encodePath(path) |
| 3679 |
self.assertTrue(isinstance(safePath, str)) |
| 3680 |
self.assertEqual(path, safePath) |
| 3681 |
|
| 3682 |
def testEncodePath_003(self): |
| 3683 |
""" |
| 3684 |
Test with an simple string, an ascii word. |
| 3685 |
""" |
| 3686 |
path = "whatever" |
| 3687 |
safePath = encodePath(path) |
| 3688 |
self.assertTrue(isinstance(safePath, str)) |
| 3689 |
self.assertEqual(path, safePath) |
| 3690 |
|
| 3691 |
def testEncodePath_004(self): |
| 3692 |
""" |
| 3693 |
Test with simple string, a complete path. |
| 3694 |
""" |
| 3695 |
path = "/usr/share/doc/xmltv/README.Debian" |
| 3696 |
safePath = encodePath(path) |
| 3697 |
self.assertTrue(isinstance(safePath, str)) |
| 3698 |
self.assertEqual(path, safePath) |
| 3699 |
|
| 3700 |
def testEncodePath_005(self): |
| 3701 |
""" |
| 3702 |
Test with simple string, a non-ascii path. |
| 3703 |
""" |
| 3704 |
path = "\xe2\x99\xaa\xe2\x99\xac" |
| 3705 |
safePath = encodePath(path) |
| 3706 |
self.assertTrue(isinstance(safePath, str)) |
| 3707 |
self.assertEqual(path, safePath) |
| 3708 |
|
| 3709 |
def testEncodePath_006(self): |
| 3710 |
""" |
| 3711 |
Test with a simple string, empty. |
| 3712 |
""" |
| 3713 |
path = "" |
| 3714 |
safePath = encodePath(path) |
| 3715 |
self.assertTrue(isinstance(safePath, str)) |
| 3716 |
self.assertEqual(path, safePath) |
| 3717 |
|
| 3718 |
def testEncodePath_007(self): |
| 3719 |
""" |
| 3720 |
Test with an simple string, an ascii word. |
| 3721 |
""" |
| 3722 |
path = "whatever" |
| 3723 |
safePath = encodePath(path) |
| 3724 |
self.assertTrue(isinstance(safePath, str)) |
| 3725 |
self.assertEqual(path, safePath) |
| 3726 |
|
| 3727 |
def testEncodePath_008(self): |
| 3728 |
""" |
| 3729 |
Test with simple string, a complete path. |
| 3730 |
""" |
| 3731 |
path = "/usr/share/doc/xmltv/README.Debian" |
| 3732 |
safePath = encodePath(path) |
| 3733 |
self.assertTrue(isinstance(safePath, str)) |
| 3734 |
self.assertEqual(path, safePath) |
| 3735 |
|
| 3736 |
def testEncodePath_009(self): |
| 3737 |
""" |
| 3738 |
Test with simple string, a non-ascii path. |
| 3739 |
""" |
| 3740 |
path = "\xe2\x99\xaa\xe2\x99\xac" |
| 3741 |
safePath = encodePath(path) |
| 3742 |
self.assertTrue(isinstance(safePath, str)) |
| 3743 |
self.assertEqual("\xe2\x99\xaa\xe2\x99\xac", safePath) |
| 3744 |
|
| 3745 |
##################### |
| 3746 |
# Test convertSize() |
| 3747 |
###################### |
| 3748 |
|
| 3749 |
def testConvertSize_001(self): |
| 3750 |
""" |
| 3751 |
Test valid conversion from bytes to bytes. |
| 3752 |
""" |
| 3753 |
fromUnit = UNIT_BYTES |
| 3754 |
toUnit = UNIT_BYTES |
| 3755 |
size = 10.0 |
| 3756 |
result = convertSize(size, fromUnit, toUnit) |
| 3757 |
self.assertEqual(result, size) |
| 3758 |
|
| 3759 |
def testConvertSize_002(self): |
| 3760 |
""" |
| 3761 |
Test valid conversion from sectors to bytes and back. |
| 3762 |
""" |
| 3763 |
fromUnit = UNIT_SECTORS |
| 3764 |
toUnit = UNIT_BYTES |
| 3765 |
size = 10 |
| 3766 |
result1 = convertSize(size, fromUnit, toUnit) |
| 3767 |
self.assertEqual(10 * 2048, result1) |
| 3768 |
result2 = convertSize(result1, toUnit, fromUnit) |
| 3769 |
self.assertEqual(result2, size) |
| 3770 |
|
| 3771 |
def testConvertSize_003(self): |
| 3772 |
""" |
| 3773 |
Test valid conversion from kbytes to bytes and back. |
| 3774 |
""" |
| 3775 |
fromUnit = UNIT_KBYTES |
| 3776 |
toUnit = UNIT_BYTES |
| 3777 |
size = 10 |
| 3778 |
result1 = convertSize(size, fromUnit, toUnit) |
| 3779 |
self.assertEqual(10 * 1024, result1) |
| 3780 |
result2 = convertSize(result1, toUnit, fromUnit) |
| 3781 |
self.assertEqual(result2, size) |
| 3782 |
|
| 3783 |
def testConvertSize_004(self): |
| 3784 |
""" |
| 3785 |
Test valid conversion from mbytes to bytes and back. |
| 3786 |
""" |
| 3787 |
fromUnit = UNIT_MBYTES |
| 3788 |
toUnit = UNIT_BYTES |
| 3789 |
size = 10 |
| 3790 |
result1 = convertSize(size, fromUnit, toUnit) |
| 3791 |
self.assertEqual(10 * 1024 * 1024, result1) |
| 3792 |
result2 = convertSize(result1, toUnit, fromUnit) |
| 3793 |
self.assertEqual(result2, size) |
| 3794 |
|
| 3795 |
def testConvertSize_005(self): |
| 3796 |
""" |
| 3797 |
Test valid conversion from gbytes to bytes and back. |
| 3798 |
""" |
| 3799 |
fromUnit = UNIT_GBYTES |
| 3800 |
toUnit = UNIT_BYTES |
| 3801 |
size = 10 |
| 3802 |
result1 = convertSize(size, fromUnit, toUnit) |
| 3803 |
self.assertEqual(10 * 1024 * 1024 * 1024, result1) |
| 3804 |
result2 = convertSize(result1, toUnit, fromUnit) |
| 3805 |
self.assertEqual(result2, size) |
| 3806 |
|
| 3807 |
def testConvertSize_006(self): |
| 3808 |
""" |
| 3809 |
Test valid conversion from mbytes to kbytes and back. |
| 3810 |
""" |
| 3811 |
fromUnit = UNIT_MBYTES |
| 3812 |
toUnit = UNIT_KBYTES |
| 3813 |
size = 10 |
| 3814 |
result1 = convertSize(size, fromUnit, toUnit) |
| 3815 |
self.assertEqual(size * 1024, result1) |
| 3816 |
result2 = convertSize(result1, toUnit, fromUnit) |
| 3817 |
self.assertEqual(result2, size) |
| 3818 |
|
| 3819 |
def testConvertSize_007(self): |
| 3820 |
""" |
| 3821 |
Test with an invalid from unit (None). |
| 3822 |
""" |
| 3823 |
fromUnit = None |
| 3824 |
toUnit = UNIT_BYTES |
| 3825 |
size = 10 |
| 3826 |
self.assertRaises(ValueError, convertSize, size, fromUnit, toUnit) |
| 3827 |
|
| 3828 |
def testConvertSize_008(self): |
| 3829 |
""" |
| 3830 |
Test with an invalid from unit. |
| 3831 |
""" |
| 3832 |
fromUnit = 333 |
| 3833 |
toUnit = UNIT_BYTES |
| 3834 |
size = 10 |
| 3835 |
self.assertRaises(ValueError, convertSize, size, fromUnit, toUnit) |
| 3836 |
|
| 3837 |
def testConvertSize_009(self): |
| 3838 |
""" |
| 3839 |
Test with an invalid to unit (None) |
| 3840 |
""" |
| 3841 |
fromUnit = UNIT_BYTES |
| 3842 |
toUnit = None |
| 3843 |
size = 10 |
| 3844 |
self.assertRaises(ValueError, convertSize, size, fromUnit, toUnit) |
| 3845 |
|
| 3846 |
def testConvertSize_010(self): |
| 3847 |
""" |
| 3848 |
Test with an invalid to unit. |
| 3849 |
""" |
| 3850 |
fromUnit = UNIT_BYTES |
| 3851 |
toUnit = "ken" |
| 3852 |
size = 10 |
| 3853 |
self.assertRaises(ValueError, convertSize, size, fromUnit, toUnit) |
| 3854 |
|
| 3855 |
def testConvertSize_011(self): |
| 3856 |
""" |
| 3857 |
Test with an invalid quantity (None) |
| 3858 |
""" |
| 3859 |
fromUnit = UNIT_BYTES |
| 3860 |
toUnit = UNIT_BYTES |
| 3861 |
size = None |
| 3862 |
self.assertRaises(ValueError, convertSize, size, fromUnit, toUnit) |
| 3863 |
|
| 3864 |
def testConvertSize_012(self): |
| 3865 |
""" |
| 3866 |
Test with an invalid quantity (not a floating point). |
| 3867 |
""" |
| 3868 |
fromUnit = UNIT_BYTES |
| 3869 |
toUnit = UNIT_BYTES |
| 3870 |
size = "blech" |
| 3871 |
self.assertRaises(ValueError, convertSize, size, fromUnit, toUnit) |
| 3872 |
|
| 3873 |
#################### |
| 3874 |
# Test nullDevice() |
| 3875 |
##################### |
| 3876 |
|
| 3877 |
def testNullDevice_001(self): |
| 3878 |
""" |
| 3879 |
Test that the function behaves sensibly. |
| 3880 |
""" |
| 3881 |
device = nullDevice() |
| 3882 |
if sys.platform == "win32": |
| 3883 |
self.assertEqual("nul", device) |
| 3884 |
else: |
| 3885 |
self.assertEqual("/dev/null", device) |
| 3886 |
|
| 3887 |
###################### |
| 3888 |
# Test displayBytes() |
| 3889 |
###################### |
| 3890 |
|
| 3891 |
def testDisplayBytes_001(self): |
| 3892 |
""" |
| 3893 |
Test display for a positive value < 1 KB |
| 3894 |
""" |
| 3895 |
bytes = 12 |
| 3896 |
result = displayBytes(bytes) |
| 3897 |
self.assertEqual("12 bytes", result) |
| 3898 |
result = displayBytes(bytes, 3) |
| 3899 |
self.assertEqual("12 bytes", result) |
| 3900 |
|
| 3901 |
def testDisplayBytes_002(self): |
| 3902 |
""" |
| 3903 |
Test display for a negative value < 1 KB |
| 3904 |
""" |
| 3905 |
bytes = -12 |
| 3906 |
result = displayBytes(bytes) |
| 3907 |
self.assertEqual("-12 bytes", result) |
| 3908 |
result = displayBytes(bytes, 3) |
| 3909 |
self.assertEqual("-12 bytes", result) |
| 3910 |
|
| 3911 |
def testDisplayBytes_003(self): |
| 3912 |
""" |
| 3913 |
Test display for a positive value = 1kB |
| 3914 |
""" |
| 3915 |
bytes = 1024 |
| 3916 |
result = displayBytes(bytes) |
| 3917 |
self.assertEqual("1.00 kB", result) |
| 3918 |
result = displayBytes(bytes, 3) |
| 3919 |
self.assertEqual("1.000 kB", result) |
| 3920 |
|
| 3921 |
def testDisplayBytes_004(self): |
| 3922 |
""" |
| 3923 |
Test display for a positive value >= 1kB |
| 3924 |
""" |
| 3925 |
bytes = 5678 |
| 3926 |
result = displayBytes(bytes) |
| 3927 |
self.assertEqual("5.54 kB", result) |
| 3928 |
result = displayBytes(bytes, 3) |
| 3929 |
self.assertEqual("5.545 kB", result) |
| 3930 |
|
| 3931 |
def testDisplayBytes_005(self): |
| 3932 |
""" |
| 3933 |
Test display for a negative value >= 1kB |
| 3934 |
""" |
| 3935 |
bytes = -5678 |
| 3936 |
result = displayBytes(bytes) |
| 3937 |
self.assertEqual("-5.54 kB", result) |
| 3938 |
result = displayBytes(bytes, 3) |
| 3939 |
self.assertEqual("-5.545 kB", result) |
| 3940 |
|
| 3941 |
def testDisplayBytes_006(self): |
| 3942 |
""" |
| 3943 |
Test display for a positive value = 1MB |
| 3944 |
""" |
| 3945 |
bytes = 1024.0 * 1024.0 |
| 3946 |
result = displayBytes(bytes) |
| 3947 |
self.assertEqual("1.00 MB", result) |
| 3948 |
result = displayBytes(bytes, 3) |
| 3949 |
self.assertEqual("1.000 MB", result) |
| 3950 |
|
| 3951 |
def testDisplayBytes_007(self): |
| 3952 |
""" |
| 3953 |
Test display for a positive value >= 1MB |
| 3954 |
""" |
| 3955 |
bytes = 72372224 |
| 3956 |
result = displayBytes(bytes) |
| 3957 |
self.assertEqual("69.02 MB", result) |
| 3958 |
result = displayBytes(bytes, 3) |
| 3959 |
self.assertEqual("69.020 MB", result) |
| 3960 |
|
| 3961 |
def testDisplayBytes_008(self): |
| 3962 |
""" |
| 3963 |
Test display for a negative value >= 1MB |
| 3964 |
""" |
| 3965 |
bytes = -72372224.0 |
| 3966 |
result = displayBytes(bytes) |
| 3967 |
self.assertEqual("-69.02 MB", result) |
| 3968 |
result = displayBytes(bytes, 3) |
| 3969 |
self.assertEqual("-69.020 MB", result) |
| 3970 |
|
| 3971 |
def testDisplayBytes_009(self): |
| 3972 |
""" |
| 3973 |
Test display for a positive value = 1GB |
| 3974 |
""" |
| 3975 |
bytes = 1024.0 * 1024.0 * 1024.0 |
| 3976 |
result = displayBytes(bytes) |
| 3977 |
self.assertEqual("1.00 GB", result) |
| 3978 |
result = displayBytes(bytes, 3) |
| 3979 |
self.assertEqual("1.000 GB", result) |
| 3980 |
|
| 3981 |
def testDisplayBytes_010(self): |
| 3982 |
""" |
| 3983 |
Test display for a positive value >= 1GB |
| 3984 |
""" |
| 3985 |
bytes = 4.4 * 1024.0 * 1024.0 * 1024.0 |
| 3986 |
result = displayBytes(bytes) |
| 3987 |
self.assertEqual("4.40 GB", result) |
| 3988 |
result = displayBytes(bytes, 3) |
| 3989 |
self.assertEqual("4.400 GB", result) |
| 3990 |
|
| 3991 |
def testDisplayBytes_011(self): |
| 3992 |
""" |
| 3993 |
Test display for a negative value >= 1GB |
| 3994 |
""" |
| 3995 |
bytes = -1234567891011 |
| 3996 |
result = displayBytes(bytes) |
| 3997 |
self.assertEqual("-1149.78 GB", result) |
| 3998 |
result = displayBytes(bytes, 3) |
| 3999 |
self.assertEqual("-1149.781 GB", result) |
| 4000 |
|
| 4001 |
def testDisplayBytes_012(self): |
| 4002 |
""" |
| 4003 |
Test display with an invalid quantity (None). |
| 4004 |
""" |
| 4005 |
bytes = None |
| 4006 |
self.assertRaises(ValueError, displayBytes, bytes) |
| 4007 |
|
| 4008 |
def testDisplayBytes_013(self): |
| 4009 |
""" |
| 4010 |
Test display with an invalid quantity (not a floating point). |
| 4011 |
""" |
| 4012 |
bytes = "ken" |
| 4013 |
self.assertRaises(ValueError, displayBytes, bytes) |
| 4014 |
|
| 4015 |
######################### |
| 4016 |
# Test deriveDayOfWeek() |
| 4017 |
######################### |
| 4018 |
|
| 4019 |
def testDeriveDayOfWeek_001(self): |
| 4020 |
""" |
| 4021 |
Test for valid day names. |
| 4022 |
""" |
| 4023 |
self.assertEqual(0, deriveDayOfWeek("monday")) |
| 4024 |
self.assertEqual(1, deriveDayOfWeek("tuesday")) |
| 4025 |
self.assertEqual(2, deriveDayOfWeek("wednesday")) |
| 4026 |
self.assertEqual(3, deriveDayOfWeek("thursday")) |
| 4027 |
self.assertEqual(4, deriveDayOfWeek("friday")) |
| 4028 |
self.assertEqual(5, deriveDayOfWeek("saturday")) |
| 4029 |
self.assertEqual(6, deriveDayOfWeek("sunday")) |
| 4030 |
|
| 4031 |
def testDeriveDayOfWeek_002(self): |
| 4032 |
""" |
| 4033 |
Test for invalid day names. |
| 4034 |
""" |
| 4035 |
self.assertEqual(-1, deriveDayOfWeek("bogus")) |
| 4036 |
|
| 4037 |
####################### |
| 4038 |
# Test isStartOfWeek() |
| 4039 |
####################### |
| 4040 |
|
| 4041 |
# noinspection PyUnboundLocalVariable |
| 4042 |
def testIsStartOfWeek001(self): |
| 4043 |
""" |
| 4044 |
Test positive case. |
| 4045 |
""" |
| 4046 |
day = time.localtime().tm_wday |
| 4047 |
if day == 0: |
| 4048 |
result = isStartOfWeek("monday") |
| 4049 |
elif day == 1: |
| 4050 |
result = isStartOfWeek("tuesday") |
| 4051 |
elif day == 2: |
| 4052 |
result = isStartOfWeek("wednesday") |
| 4053 |
elif day == 3: |
| 4054 |
result = isStartOfWeek("thursday") |
| 4055 |
elif day == 4: |
| 4056 |
result = isStartOfWeek("friday") |
| 4057 |
elif day == 5: |
| 4058 |
result = isStartOfWeek("saturday") |
| 4059 |
elif day == 6: |
| 4060 |
result = isStartOfWeek("sunday") |
| 4061 |
self.assertEqual(True, result) |
| 4062 |
|
| 4063 |
# noinspection PyUnboundLocalVariable |
| 4064 |
def testIsStartOfWeek002(self): |
| 4065 |
""" |
| 4066 |
Test negative case. |
| 4067 |
""" |
| 4068 |
day = time.localtime().tm_wday |
| 4069 |
if day == 0: |
| 4070 |
result = isStartOfWeek("friday") |
| 4071 |
elif day == 1: |
| 4072 |
result = isStartOfWeek("saturday") |
| 4073 |
elif day == 2: |
| 4074 |
result = isStartOfWeek("sunday") |
| 4075 |
elif day == 3: |
| 4076 |
result = isStartOfWeek("monday") |
| 4077 |
elif day == 4: |
| 4078 |
result = isStartOfWeek("tuesday") |
| 4079 |
elif day == 5: |
| 4080 |
result = isStartOfWeek("wednesday") |
| 4081 |
elif day == 6: |
| 4082 |
result = isStartOfWeek("thursday") |
| 4083 |
self.assertEqual(False, result) |
| 4084 |
|
| 4085 |
############################# |
| 4086 |
# Test buildNormalizedPath() |
| 4087 |
############################# |
| 4088 |
|
| 4089 |
def testBuildNormalizedPath001(self): |
| 4090 |
""" |
| 4091 |
Test for a None path. |
| 4092 |
""" |
| 4093 |
self.assertRaises(ValueError, buildNormalizedPath, None) |
| 4094 |
|
| 4095 |
def testBuildNormalizedPath002(self): |
| 4096 |
""" |
| 4097 |
Test for an empty path. |
| 4098 |
""" |
| 4099 |
path = "" |
| 4100 |
expected = "" |
| 4101 |
actual = buildNormalizedPath(path) |
| 4102 |
self.assertEqual(expected, actual) |
| 4103 |
|
| 4104 |
def testBuildNormalizedPath003(self): |
| 4105 |
""" |
| 4106 |
Test for "." |
| 4107 |
""" |
| 4108 |
path = "." |
| 4109 |
expected = "_" |
| 4110 |
actual = buildNormalizedPath(path) |
| 4111 |
self.assertEqual(expected, actual) |
| 4112 |
|
| 4113 |
def testBuildNormalizedPath004(self): |
| 4114 |
""" |
| 4115 |
Test for ".." |
| 4116 |
""" |
| 4117 |
path = ".." |
| 4118 |
expected = "_." |
| 4119 |
actual = buildNormalizedPath(path) |
| 4120 |
self.assertEqual(expected, actual) |
| 4121 |
|
| 4122 |
def testBuildNormalizedPath005(self): |
| 4123 |
""" |
| 4124 |
Test for "..........." |
| 4125 |
""" |
| 4126 |
path = ".........." |
| 4127 |
expected = "_........." |
| 4128 |
actual = buildNormalizedPath(path) |
| 4129 |
self.assertEqual(expected, actual) |
| 4130 |
|
| 4131 |
def testBuildNormalizedPath006(self): |
| 4132 |
""" |
| 4133 |
Test for "/" |
| 4134 |
""" |
| 4135 |
path = "/" |
| 4136 |
expected = "_" |
| 4137 |
actual = buildNormalizedPath(path) |
| 4138 |
self.assertEqual(expected, actual) |
| 4139 |
|
| 4140 |
def testBuildNormalizedPath007(self): |
| 4141 |
""" |
| 4142 |
Test for "\\" |
| 4143 |
""" |
| 4144 |
path = "\\" |
| 4145 |
expected = "_" |
| 4146 |
actual = buildNormalizedPath(path) |
| 4147 |
self.assertEqual(expected, actual) |
| 4148 |
|
| 4149 |
def testBuildNormalizedPath008(self): |
| 4150 |
""" |
| 4151 |
Test for "/." |
| 4152 |
""" |
| 4153 |
path = "/." |
| 4154 |
expected = "_" |
| 4155 |
actual = buildNormalizedPath(path) |
| 4156 |
self.assertEqual(expected, actual) |
| 4157 |
|
| 4158 |
def testBuildNormalizedPath009(self): |
| 4159 |
""" |
| 4160 |
Test for "/.." |
| 4161 |
""" |
| 4162 |
path = "/.." |
| 4163 |
expected = "_." |
| 4164 |
actual = buildNormalizedPath(path) |
| 4165 |
self.assertEqual(expected, actual) |
| 4166 |
|
| 4167 |
def testBuildNormalizedPath010(self): |
| 4168 |
""" |
| 4169 |
Test for "/..." |
| 4170 |
""" |
| 4171 |
path = "/..." |
| 4172 |
expected = "_.." |
| 4173 |
actual = buildNormalizedPath(path) |
| 4174 |
self.assertEqual(expected, actual) |
| 4175 |
|
| 4176 |
def testBuildNormalizedPath011(self): |
| 4177 |
r""" |
| 4178 |
Test for "\." |
| 4179 |
""" |
| 4180 |
path = r"\." |
| 4181 |
expected = "_" |
| 4182 |
actual = buildNormalizedPath(path) |
| 4183 |
self.assertEqual(expected, actual) |
| 4184 |
|
| 4185 |
def testBuildNormalizedPath012(self): |
| 4186 |
r""" |
| 4187 |
Test for "\.." |
| 4188 |
""" |
| 4189 |
path = r"\.." |
| 4190 |
expected = "_." |
| 4191 |
actual = buildNormalizedPath(path) |
| 4192 |
self.assertEqual(expected, actual) |
| 4193 |
|
| 4194 |
def testBuildNormalizedPath013(self): |
| 4195 |
r""" |
| 4196 |
Test for "\..." |
| 4197 |
""" |
| 4198 |
path = r"\..." |
| 4199 |
expected = "_.." |
| 4200 |
actual = buildNormalizedPath(path) |
| 4201 |
self.assertEqual(expected, actual) |
| 4202 |
|
| 4203 |
def testBuildNormalizedPath014(self): |
| 4204 |
""" |
| 4205 |
Test for "/var/log/apache/httpd.log.1" |
| 4206 |
""" |
| 4207 |
path = "/var/log/apache/httpd.log.1" |
| 4208 |
expected = "var-log-apache-httpd.log.1" |
| 4209 |
actual = buildNormalizedPath(path) |
| 4210 |
self.assertEqual(expected, actual) |
| 4211 |
|
| 4212 |
def testBuildNormalizedPath015(self): |
| 4213 |
""" |
| 4214 |
Test for "var/log/apache/httpd.log.1" |
| 4215 |
""" |
| 4216 |
path = "var/log/apache/httpd.log.1" |
| 4217 |
expected = "var-log-apache-httpd.log.1" |
| 4218 |
actual = buildNormalizedPath(path) |
| 4219 |
self.assertEqual(expected, actual) |
| 4220 |
|
| 4221 |
def testBuildNormalizedPath016(self): |
| 4222 |
""" |
| 4223 |
Test for "\\var/log/apache\\httpd.log.1" |
| 4224 |
""" |
| 4225 |
path = "\\var/log/apache\\httpd.log.1" |
| 4226 |
expected = "var-log-apache-httpd.log.1" |
| 4227 |
actual = buildNormalizedPath(path) |
| 4228 |
self.assertEqual(expected, actual) |
| 4229 |
|
| 4230 |
def testBuildNormalizedPath017(self): |
| 4231 |
""" |
| 4232 |
Test for "/Big Nasty Base Path With Spaces/something/else/space s/file. log .2 ." |
| 4233 |
""" |
| 4234 |
path = "/Big Nasty Base Path With Spaces/something/else/space s/file. log .2 ." |
| 4235 |
expected = "Big_Nasty_Base_Path_With_Spaces-something-else-space_s-file.__log___.2_." |
| 4236 |
actual = buildNormalizedPath(path) |
| 4237 |
self.assertEqual(expected, actual) |
| 4238 |
|
| 4239 |
def testBuildNormalizedPath018(self): |
| 4240 |
""" |
| 4241 |
Test for Windows path with drive letter and slashes. |
| 4242 |
""" |
| 4243 |
path = "c:/Users/pronovic/projects/repos" |
| 4244 |
expected = "c-Users-pronovic-projects-repos" |
| 4245 |
actual = buildNormalizedPath(path) |
| 4246 |
self.assertEqual(expected, actual) |
| 4247 |
|
| 4248 |
def testBuildNormalizedPath019(self): |
| 4249 |
""" |
| 4250 |
Test for Windows path with drive letter and backslashes. |
| 4251 |
""" |
| 4252 |
path = r"c:\Users\pronovic\projects\repos" |
| 4253 |
expected = "c-Users-pronovic-projects-repos" |
| 4254 |
actual = buildNormalizedPath(path) |
| 4255 |
self.assertEqual(expected, actual) |
| 4256 |
|
| 4257 |
def testBuildNormalizedPath020(self): |
| 4258 |
""" |
| 4259 |
Test for path with embedded colon. |
| 4260 |
""" |
| 4261 |
path = "/path/to/whatever/key:value" |
| 4262 |
expected = "path-to-whatever-key_value" |
| 4263 |
actual = buildNormalizedPath(path) |
| 4264 |
self.assertEqual(expected, actual) |
| 4265 |
|
| 4266 |
########################## |
| 4267 |
# Test splitCommandLine() |
| 4268 |
########################## |
| 4269 |
|
| 4270 |
def testSplitCommandLine_001(self): |
| 4271 |
""" |
| 4272 |
Test for a None command line. |
| 4273 |
""" |
| 4274 |
commandLine = None |
| 4275 |
self.assertRaises(ValueError, splitCommandLine, commandLine) |
| 4276 |
|
| 4277 |
def testSplitCommandLine_002(self): |
| 4278 |
""" |
| 4279 |
Test for an empty command line. |
| 4280 |
""" |
| 4281 |
commandLine = "" |
| 4282 |
result = splitCommandLine(commandLine) |
| 4283 |
self.assertEqual([], result) |
| 4284 |
|
| 4285 |
def testSplitCommandLine_003(self): |
| 4286 |
""" |
| 4287 |
Test for a command line with no quoted arguments. |
| 4288 |
""" |
| 4289 |
commandLine = "cback --verbose stage store purge" |
| 4290 |
result = splitCommandLine(commandLine) |
| 4291 |
self.assertEqual(["cback", "--verbose", "stage", "store", "purge"], result) |
| 4292 |
|
| 4293 |
def testSplitCommandLine_004(self): |
| 4294 |
""" |
| 4295 |
Test for a command line with double-quoted arguments. |
| 4296 |
""" |
| 4297 |
commandLine = 'cback "this is a really long double-quoted argument"' |
| 4298 |
result = splitCommandLine(commandLine) |
| 4299 |
self.assertEqual(["cback", "this is a really long double-quoted argument"], result) |
| 4300 |
|
| 4301 |
def testSplitCommandLine_005(self): |
| 4302 |
""" |
| 4303 |
Test for a command line with single-quoted arguments. |
| 4304 |
""" |
| 4305 |
commandLine = "cback 'this is a really long single-quoted argument'" |
| 4306 |
result = splitCommandLine(commandLine) |
| 4307 |
self.assertEqual(["cback", "'this", "is", "a", "really", "long", "single-quoted", "argument'"], result) |
| 4308 |
|
| 4309 |
######################### |
| 4310 |
# Test dereferenceLink() |
| 4311 |
######################### |
| 4312 |
|
| 4313 |
@unittest.skipUnless(platformSupportsLinks(), "Requires soft links") |
| 4314 |
def testDereferenceLink_001(self): |
| 4315 |
""" |
| 4316 |
Test for a path that is a link, absolute=false. |
| 4317 |
""" |
| 4318 |
self.extractTar("tree10") |
| 4319 |
path = self.buildPath(["tree10", "link002"]) |
| 4320 |
expected = "file002" |
| 4321 |
actual = dereferenceLink(path, absolute=False) |
| 4322 |
self.assertEqual(expected, actual) |
| 4323 |
|
| 4324 |
@unittest.skipUnless(platformSupportsLinks(), "Requires soft links") |
| 4325 |
def testDereferenceLink_002(self): |
| 4326 |
""" |
| 4327 |
Test for a path that is a link, absolute=true. |
| 4328 |
""" |
| 4329 |
self.extractTar("tree10") |
| 4330 |
path = self.buildPath(["tree10", "link002"]) |
| 4331 |
expected = self.buildPath(["tree10", "file002"]) |
| 4332 |
actual = dereferenceLink(path) |
| 4333 |
self.assertEqual(expected, actual) |
| 4334 |
actual = dereferenceLink(path, absolute=True) |
| 4335 |
self.assertEqual(expected, actual) |
| 4336 |
|
| 4337 |
def testDereferenceLink_003(self): |
| 4338 |
""" |
| 4339 |
Test for a path that is a file (not a link), absolute=false. |
| 4340 |
""" |
| 4341 |
self.extractTar("tree10") |
| 4342 |
path = self.buildPath(["tree10", "file001"]) |
| 4343 |
expected = path |
| 4344 |
actual = dereferenceLink(path, absolute=False) |
| 4345 |
self.assertEqual(expected, actual) |
| 4346 |
|
| 4347 |
def testDereferenceLink_004(self): |
| 4348 |
""" |
| 4349 |
Test for a path that is a file (not a link), absolute=true. |
| 4350 |
""" |
| 4351 |
self.extractTar("tree10") |
| 4352 |
path = self.buildPath(["tree10", "file001"]) |
| 4353 |
expected = path |
| 4354 |
actual = dereferenceLink(path) |
| 4355 |
self.assertEqual(expected, actual) |
| 4356 |
actual = dereferenceLink(path, absolute=True) |
| 4357 |
self.assertEqual(expected, actual) |
| 4358 |
|
| 4359 |
def testDereferenceLink_005(self): |
| 4360 |
""" |
| 4361 |
Test for a path that is a directory (not a link), absolute=false. |
| 4362 |
""" |
| 4363 |
self.extractTar("tree10") |
| 4364 |
path = self.buildPath(["tree10", "dir001"]) |
| 4365 |
expected = path |
| 4366 |
actual = dereferenceLink(path, absolute=False) |
| 4367 |
self.assertEqual(expected, actual) |
| 4368 |
|
| 4369 |
def testDereferenceLink_006(self): |
| 4370 |
""" |
| 4371 |
Test for a path that is a directory (not a link), absolute=true. |
| 4372 |
""" |
| 4373 |
self.extractTar("tree10") |
| 4374 |
path = self.buildPath(["tree10", "dir001"]) |
| 4375 |
expected = path |
| 4376 |
actual = dereferenceLink(path) |
| 4377 |
self.assertEqual(expected, actual) |
| 4378 |
actual = dereferenceLink(path, absolute=True) |
| 4379 |
self.assertEqual(expected, actual) |
| 4380 |
|
| 4381 |
def testDereferenceLink_007(self): |
| 4382 |
""" |
| 4383 |
Test for a path that does not exist, absolute=false. |
| 4384 |
""" |
| 4385 |
self.extractTar("tree10") |
| 4386 |
path = self.buildPath(["tree10", "blech"]) |
| 4387 |
expected = path |
| 4388 |
actual = dereferenceLink(path, absolute=False) |
| 4389 |
self.assertEqual(expected, actual) |
| 4390 |
|
| 4391 |
def testDereferenceLink_008(self): |
| 4392 |
""" |
| 4393 |
Test for a path that does not exist, absolute=true. |
| 4394 |
""" |
| 4395 |
self.extractTar("tree10") |
| 4396 |
path = self.buildPath(["tree10", "blech"]) |
| 4397 |
expected = path |
| 4398 |
actual = dereferenceLink(path) |
| 4399 |
self.assertEqual(expected, actual) |
| 4400 |
actual = dereferenceLink(path, absolute=True) |
| 4401 |
self.assertEqual(expected, actual) |
| 4402 |
|
| 4403 |
################################### |
| 4404 |
# Test parseCommaSeparatedString() |
| 4405 |
################################### |
| 4406 |
|
| 4407 |
def testParseCommaSeparatedString_001(self): |
| 4408 |
""" |
| 4409 |
Test parseCommaSeparatedString() for a None string. |
| 4410 |
""" |
| 4411 |
actual = parseCommaSeparatedString(None) |
| 4412 |
self.assertEqual(None, actual) |
| 4413 |
|
| 4414 |
def testParseCommaSeparatedString_002(self): |
| 4415 |
""" |
| 4416 |
Test parseCommaSeparatedString() for an empty string. |
| 4417 |
""" |
| 4418 |
actual = parseCommaSeparatedString("") |
| 4419 |
self.assertEqual([], actual) |
| 4420 |
|
| 4421 |
def testParseCommaSeparatedString_003(self): |
| 4422 |
""" |
| 4423 |
Test parseCommaSeparatedString() for a string with one value. |
| 4424 |
""" |
| 4425 |
actual = parseCommaSeparatedString("ken") |
| 4426 |
self.assertEqual(["ken"], actual) |
| 4427 |
|
| 4428 |
def testParseCommaSeparatedString_004(self): |
| 4429 |
""" |
| 4430 |
Test parseCommaSeparatedString() for a string with multiple values, no |
| 4431 |
spaces. |
| 4432 |
""" |
| 4433 |
actual = parseCommaSeparatedString("a,b,c") |
| 4434 |
self.assertEqual(["a", "b", "c"], actual) |
| 4435 |
|
| 4436 |
def testParseCommaSeparatedString_005(self): |
| 4437 |
""" |
| 4438 |
Test parseCommaSeparatedString() for a string with multiple values, with |
| 4439 |
spaces. |
| 4440 |
""" |
| 4441 |
actual = parseCommaSeparatedString("a, b, c") |
| 4442 |
self.assertEqual(["a", "b", "c"], actual) |
| 4443 |
|
| 4444 |
def testParseCommaSeparatedString_006(self): |
| 4445 |
""" |
| 4446 |
Test parseCommaSeparatedString() for a string with multiple values, |
| 4447 |
worst-case kind of value. |
| 4448 |
""" |
| 4449 |
actual = parseCommaSeparatedString(" one, two,three, four , five , six, seven,,eight ,") |
| 4450 |
self.assertEqual(["one", "two", "three", "four", "five", "six", "seven", "eight"], actual) |