示例#1
0
    def test_instrument_dump(self):
        enable_test_value = False
        dump_path_value = "/tmp/test.dump"
        return_value = [1, 2, 3]

        class A(object):
            enable_test = enable_test_value
            dump_path = dump_path_value

            def __init__(self):
                self.state = 1

            @test_ut.instrument_dump
            def meth_test(self):
                return return_value

        a = A()
        a.meth_test()
        self.should_raise("There was a dump file found in %s. "
                          "It might be leftover from previous test."
                          % dump_path_value, du.pick_load, dump_path_value)

        A.enable_test = True
        a.meth_test()
        dump = du.pick_load(dump_path_value)

        obs_value = dump[0][1]
        exp_return = return_value
        self.assertEqual(obs_value, exp_return,
                         "Return values do not match: %s != %s"
                         % (obs_value, exp_return))
        fu.removefile(dump_path_value)
    def test_instrument_dump(self):
        enable_test_value = False
        dump_path_value = "/tmp/test.dump"
        return_value = [1, 2, 3]

        class A(object):
            enable_test = enable_test_value
            dump_path = dump_path_value

            def __init__(self):
                self.state = 1

            @test_ut.instrument_dump
            def meth_test(self):
                return return_value

        a = A()
        a.meth_test()
        self.should_raise(
            "There was a dump file found in %s. "
            "It might be leftover from previous test." % dump_path_value,
            du.pick_load, dump_path_value)

        A.enable_test = True
        a.meth_test()
        dump = du.pick_load(dump_path_value)

        obs_value = dump[0][1]
        exp_return = return_value
        self.assertEqual(
            obs_value, exp_return,
            "Return values do not match: %s != %s" % (obs_value, exp_return))
        fu.removefile(dump_path_value)
def check_pickable(obj):
    """Checks if object can be (c)pickled."""
    # TESTME!
    temp_file = join(const.TEMP_DIR, str(timestamp()) + "tmp")
    try:
        pick_dump(obj, temp_file)
    except:
        return False
    finally:
        try:
            removefile(temp_file)
        except Exception as e:
            log.error("The file %s could not be removed: %s", temp_file, e)
    return True
示例#4
0
def check_pickable(obj):
    """Checks if object can be (c)pickled."""
    # TESTME!
    temp_file = join(const.TEMP_DIR, str(timestamp()) + "tmp")
    try:
        pick_dump(obj, temp_file)
    except:
        return False
    finally:
        try:
            removefile(temp_file)
        except Exception as e:
            log.error("The file %s could not be removed: %s",
                      temp_file, e)
    return True
示例#5
0
def clean_test_setting():
    """Clean folders and processes."""
    processes = ["tor", "obfsproxy"]
    log.info("Cleaning test setting...")
    for proc in psutil.process_iter():
        if proc.name() in processes:
            proc.kill()
            log.info(proc.name() + " killed!")
    for dirpath in DATA_DIRS.itervalues():
        log.debug("Will remove old log directory: " + dirpath)
        fu.removedir(dirpath)
    obfs_log_prefix = "obfsproxy_tester_"
    for end in ["client", "server"]:
        dirpath = join(const.TEMP_DIR, obfs_log_prefix + end + ".log")
        log.debug("Will remove old obfsproxy log file: " + dirpath)
        fu.removefile(dirpath)