Started implementing tests
This commit is contained in:
committed by
Jason Watkins
parent
4aaca80d3e
commit
9fb2274ae8
@@ -5,6 +5,8 @@ VisualStudioVersion = 12.0.31101.0
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{888888A0-9F3D-457C-B088-3A5042F75D52}") = "xplaneConnect", "xplaneConnect.pyproj", "{3C7A940D-17C8-4E91-882F-9BC8B1D2F54B}"
|
||||
EndProject
|
||||
Project("{888888A0-9F3D-457C-B088-3A5042F75D52}") = "Tests", "..\TestScripts\Python Tests\Tests.pyproj", "{6931EBB2-4E01-4C5A-86B6-668C0E75051B}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@@ -13,6 +15,8 @@ Global
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{3C7A940D-17C8-4E91-882F-9BC8B1D2F54B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{3C7A940D-17C8-4E91-882F-9BC8B1D2F54B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{6931EBB2-4E01-4C5A-86B6-668C0E75051B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{6931EBB2-4E01-4C5A-86B6-668C0E75051B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
85
TestScripts/Python Tests/Tests.py
Normal file
85
TestScripts/Python Tests/Tests.py
Normal file
@@ -0,0 +1,85 @@
|
||||
import random
|
||||
import unittest
|
||||
import imp
|
||||
|
||||
xplaneConnect = imp.load_source('xplaneConnect', '../../Python/src/xplaneConnect.py')
|
||||
|
||||
class XPCTests(unittest.TestCase):
|
||||
"""Tests the functionality of the XPlaneConnect class."""
|
||||
|
||||
def test_init(self):
|
||||
xpc = xplaneConnect.XPlaneConnect(49062, "127.0.0.1", 49009)
|
||||
self.assertTrue(True)
|
||||
|
||||
def test_close(self):
|
||||
xpc = xplaneConnect.XPlaneConnect(49063, "127.0.0.1", 49009)
|
||||
xpc.close()
|
||||
self.assertIsNone(xpc.socket)
|
||||
xpc = xplaneConnect.XPlaneConnect(49063, "127.0.0.1", 49009)
|
||||
self.assertTrue(True)
|
||||
|
||||
def test_send_read(self):
|
||||
# Init
|
||||
test = "\x00\x01\x02\x03\x05"
|
||||
|
||||
# Setup
|
||||
sender = xplaneConnect.XPlaneConnect(49064, "127.0.0.1", 49063)
|
||||
receiver = xplaneConnect.XPlaneConnect(49063, "127.0.0.1", 49009)
|
||||
|
||||
# Execution
|
||||
sender.send_udp(test)
|
||||
buf = receiver.read_udp()
|
||||
|
||||
# Cleanup
|
||||
sender.close()
|
||||
receiver.close()
|
||||
|
||||
# Tests
|
||||
for a, b in zip(test, buf):
|
||||
self.assertEqual(a, b)
|
||||
|
||||
def test_request_dref(self):
|
||||
# Init
|
||||
dref_array = []
|
||||
|
||||
# Setup
|
||||
sender = xplaneConnect.XPlaneConnect(49064, "127.0.0.1", 49009)
|
||||
dref_array.append("sim/cockpit/switches/gear_handle_status")
|
||||
dref_array.append("cockpit2/switches/panel_brightness_ratio")
|
||||
|
||||
# Execution
|
||||
result = sender.request_dref(dref_array)
|
||||
|
||||
# Cleanup
|
||||
sender.close()
|
||||
receiver.close()
|
||||
|
||||
# Tests
|
||||
self.assertEqual(2, len(result))
|
||||
self.assertEqual(1, len(result[0]))
|
||||
self.assertEqual(4, len(result[1]))
|
||||
|
||||
def test_send_dref(self):
|
||||
# Init
|
||||
dref_array = []
|
||||
|
||||
# Setup
|
||||
sender = xplaneConnect.XPlaneConnect(49066, "127.0.0.1", 49009)
|
||||
receiver = xplaneConnect.XPlaneConnect(49008, "127.0.0.1", 49009)
|
||||
dref_array.append("sim/cockpit/switches/gear_handle_status")
|
||||
|
||||
# Execution
|
||||
sender.send_dref(dref_array[0])
|
||||
result = receiver.request_dref(dref_array)
|
||||
|
||||
# Cleanup
|
||||
sender.close()
|
||||
receiver.close()
|
||||
|
||||
# Tests
|
||||
self.assertEqual(1, len(result))
|
||||
self.assertEqual(1, len(result[0]))
|
||||
self.assertEqual(0.0, result[0][0])
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
46
TestScripts/Python Tests/Tests.pyproj
Normal file
46
TestScripts/Python Tests/Tests.pyproj
Normal file
@@ -0,0 +1,46 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>6931ebb2-4e01-4c5a-86b6-668c0e75051b</ProjectGuid>
|
||||
<ProjectHome>.</ProjectHome>
|
||||
<StartupFile>Tests.py</StartupFile>
|
||||
<SearchPath>
|
||||
</SearchPath>
|
||||
<WorkingDirectory>.</WorkingDirectory>
|
||||
<OutputPath>.</OutputPath>
|
||||
<Name>Tests</Name>
|
||||
<RootNamespace>Tests</RootNamespace>
|
||||
<InterpreterId>{2af0f10d-7135-4994-9156-5d01c9c11b7e}</InterpreterId>
|
||||
<InterpreterVersion>2.7</InterpreterVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<EnableUnmanagedDebugging>false</EnableUnmanagedDebugging>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<EnableUnmanagedDebugging>false</EnableUnmanagedDebugging>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Tests.py" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<InterpreterReference Include="{2af0f10d-7135-4994-9156-5d01c9c11b7e}\2.7" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup>
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
|
||||
<PtvsTargetsFile>$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Python Tools\Microsoft.PythonTools.targets</PtvsTargetsFile>
|
||||
</PropertyGroup>
|
||||
<Import Condition="Exists($(PtvsTargetsFile))" Project="$(PtvsTargetsFile)" />
|
||||
<Import Condition="!Exists($(PtvsTargetsFile))" Project="$(MSBuildToolsPath)\Microsoft.Common.targets" />
|
||||
<!-- Uncomment the CoreCompile target to enable the Build command in
|
||||
Visual Studio and specify your pre- and post-build commands in
|
||||
the BeforeBuild and AfterBuild targets below. -->
|
||||
<!--<Target Name="CoreCompile" />-->
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
</Project>
|
||||
Reference in New Issue
Block a user