예제 #1
0
def test_stop():
    print("Stop Client:", end=" ")
    try:
        # with contextlib.redirect_stdout(None):
        c = SharedMemory("test11", 1, log='./test_client.log', client=True)
        c.close()
        assert True
        print("SUCCESSED")
    except:
        print("FAILED")
        assert False
예제 #2
0
def test_str():
    print("Create Client instance containing a \"string\":", end=" ")
    try:
        # with contextlib.redirect_stdout(None):
        c = SharedMemory("test1",
                         "azerty",
                         log='./test_client.log',
                         client=True)
        assert type(c.getValue()) is str
        assert type(c[0]) is str
        c.close()
        print("SUCCESSED")
    except:
        print("FAILED")
        assert False
예제 #3
0
def test_file():
    print("Create Client instance from JSON file:", end=" ")
    try:
        # with contextlib.redirect_stdout(None):
        c = SharedMemory(name="test9",
                         path="./tests/test.json",
                         log='./test_client.log',
                         client=True)
        res = type(c.getValue()) is dict
        c.close()
        assert res
        print("SUCCESSED")
    except:
        print("FAILED")
        assert False
예제 #4
0
def test_connection2():
    print("Create Server instance with Client(after):", end=" ")
    try:
        # with contextlib.redirect_stdout(None):
        c = SharedMemory("test27",
                         "azerty",
                         log="./test_server.log",
                         client=True)
        s = SharedMemory("test27", log="./test_server.log", client=False)
        res = c.getAvailability() and s.getAvailability()
        c.close()
        s.close()
        assert res
        print("SUCCESSED")
    except:
        print("FAILED")
        assert False
예제 #5
0
def test_availability():
    print("Check availability for Client and Server:", end=" ")
    try:
        # with contextlib.redirect_stdout(None):
        c = SharedMemory("test10",
                         "azerty",
                         log="./test_server.log",
                         client=True)
        s = SharedMemory("test10", log="./test_server.log", client=False)
        res1 = c.getAvailability() == True
        res2 = s.getAvailability() == True
        s.close()
        c.close()
        assert res1
        assert res2
        print("SUCCESSED")
    except:
        print("FAILED")
        assert False
예제 #6
0
def test_value():
    print("Server check value \"azerty\":", end=" ")
    try:
        # with contextlib.redirect_stdout(None):
        c = SharedMemory("test41",
                         "azerty",
                         log="./test_server.log",
                         client=True)
        s = SharedMemory("test41", log="./test_server.log", client=False)
        res = s.getValue() == "azerty"
        c.close()
        s.close()
        assert res
        print("SUCCESSED")
    except:
        print("FAILED")
        assert False
예제 #7
0
def test_multiStop():
    print("Server test mutli stop:", end=" ")
    try:
        # with contextlib.redirect_stdout(None):
        c = SharedMemory("test9",
                         "azerty",
                         log="./test_server.log",
                         client=True)
        s = SharedMemory("test9", log="./test_server.log", client=False)
        s.close()
        s.close()
        c.close()
        assert True
        print("SUCCESSED")
    except:
        print("FAILED")
        assert False
예제 #8
0
def test_newValue():
    print("Update Client value:", end=" ")
    try:
        # with contextlib.redirect_stdout(None):
        c = SharedMemory("test10", 1, log='./test_client.log', client=True)
        c.setValue(12)
        res1 = c.getValue() == 12
        res2 = c[0] == 12
        c.close()
        assert res1 and res2
        print("SUCCESSED")
    except:
        print("FAILED")
        assert False
예제 #9
0
def test_connection():
    print("Create Server instance without Client:", end=" ")
    try:
        # with contextlib.redirect_stdout(None):
        s = SharedMemory("test1", log="./test_server.log", client=False)
        s.getValue()
        s.close()
        assert True
        print("SUCCESSED")
    except:
        print("FAILED")
        assert False
예제 #10
0
def test_dict1():
    print("Create Client instance containing a \"dict\":", end=" ")
    try:
        # with contextlib.redirect_stdout(None):
        c = SharedMemory("test51", {'a': 1},
                         log='./test_client.log',
                         client=True)
        res1 = type(c.getValue()) is dict
        res2 = c.getType() is dict
        res3 = c.getValue()['a'] == 1
        res4 = c['a'] == 1
        c.close()
        assert res1 and res2 and res3 and res4
        print("SUCCESSED")
    except:
        print("FAILED")
        assert False
예제 #11
0
def test_bool():
    print("Create Client instance containing a \"boolean\":", end=" ")
    try:
        # with contextlib.redirect_stdout(None):
        c = SharedMemory("test41", True, log='./test_client.log', client=True)
        res1 = type(c.getValue()) is bool
        res2 = type(c[0]) is bool
        res3 = c.getValue()
        res4 = c[0]
        c.close()
        assert res1 and res2 and res3 and res4
        print("SUCCESSED")
    except:
        print("FAILED")
        assert False
예제 #12
0
def test_float():
    print("Create Client instance containing a \"float\":", end=" ")
    try:
        # with contextlib.redirect_stdout(None):
        c = SharedMemory("test31", -1.2, log='./test_client.log', client=True)
        res1 = type(c.getValue()) is float
        res2 = type(c[0]) is float
        res3 = c.getValue() == -1.2
        res4 = c[0] == -1.2
        c.close()
        assert res1 and res2 and res3 and res4
        print("SUCCESSED")
    except:
        print("FAILED")
        assert False
예제 #13
0
def test_list1():
    print("Create Client instance containing a \"list\":", end=" ")
    try:
        # with contextlib.redirect_stdout(None):
        c = SharedMemory("test61", [0, 1],
                         log='./test_client.log',
                         client=True)
        res1 = type(c.getValue()) is list
        res2 = c.getType() is list
        res3 = c.getValue()[0] == 0
        res4 = c.getValue()[1] == 1
        res5 = c[0] == 0
        res6 = c[1] == 1
        c.close()
        assert res1 and res2 and res3 and res4 and res5 and res6
        print("SUCCESSED")
    except:
        print("FAILED")
        assert False
예제 #14
0
def test_valueAccess():
    print("Deleting value from overloaded method:", end=" ")
    try:
        # with contextlib.redirect_stdout(None):
        c = SharedMemory("test13", {
            '0': 0,
            '1': 1,
            '2': 2,
            '3': 3
        },
                         log='./test_client.log',
                         client=True)
        c.restart()
        del c['0']
        c.close()
        assert True
        print("SUCCESSED")
    except:
        print("FAILED")
        assert False
예제 #15
0
def test_editValue():
    print("Server edit value \"azerty\" to \"ytreza\":", end=" ")
    try:
        # with contextlib.redirect_stdout(None):
        c = SharedMemory("test51",
                         "azerty",
                         log="./test_server.log",
                         client=True)
        s = SharedMemory("test51", log="./test_server.log", client=False)
        s.setValue("ytreza")
        res1 = c.getValue() == "ytreza"
        res2 = c[0] == "ytreza"
        c.close()
        s.close()
        assert res1
        assert res2
        print("SUCCESSED")
    except:
        print("FAILED")
        assert False
예제 #16
0
def test_serverStopped():
    print("Client test access value when Server stopped:", end=" ")
    try:
        # with contextlib.redirect_stdout(None):
        c = SharedMemory("test8",
                         "azerty",
                         log="./test_server.log",
                         client=True)
        s = SharedMemory("test8", log="./test_server.log", client=False)
        s.close()
        c.setValue("toto")
        assert c.getValue() == None
        assert c[0] == None
        c.restart()
        c.setValue("toto")
        assert c.getValue() == "toto"
        assert c[0] == "toto"
        s.restart()
        assert s.getValue() == "toto"
        assert s[0] == "toto"
        c.close()
        s.close()
        print("SUCCESSED")
    except:
        print("FAILED")
        assert False
예제 #17
0
def test_serverFirst():
    print("Create Server first:", end=" ")
    try:
        # with contextlib.redirect_stdout(None):
        s = SharedMemory("test10", log="./test_server.log", client=False)
        c = SharedMemory("test10",
                         "azerty",
                         log="./test_server.log",
                         client=True)
        res1 = c.getAvailability() == True
        res2 = s.getAvailability() == True
        assert res1
        assert res2
        assert s.getValue() == c.getValue()
        s.close()
        c.close()
        print("SUCCESSED")
    except:
        print("FAILED")
        assert False
예제 #18
0
def test_clientStopped():
    print("Server test access value when Client stopped:", end=" ")
    try:
        # with contextlib.redirect_stdout(None):
        c = SharedMemory("test62",
                         "azerty",
                         log="./test_server.log",
                         client=True)
        s = SharedMemory("test62", log="./test_server.log", client=False)
        c.close()
        s.setValue("toto")
        res1 = s.getValue() == None
        s.close()
        assert res1
        print("SUCCESSED")
    except:
        print("FAILED")
        assert False