<commit_before>#!/usr/bin/env python
PKG = 'lg_earth'
NAME = 'test_query_writer'

import rospy
import unittest
import os

from lg_earth import QueryWriter
from std_msgs.msg import String
from geometry_msgs.msg import Pose

TEST_FILE = '/tmp/query_writer_test'
TOUR_NAME = 'Amazonian Village'
EXIT_TOUR = ''
PLANET_NAME = 'mars'
SEARCH_QUERY = '10010'
TEST_POSE_LON = 20
TEST_POSE_LAT = 31.5
TEST_POSE_ALT = 22
TEST_POSE_HEADING = 270
TEST_POSE_TILT = -12
TEST_POSE_ROLL = 0
TEST_POSE_RANGE = 5000
FLYTO_KML = '<Camera><latitude>{}</latitude><longitude>{}</longitude><altitude>{}</altitude><heading>{}</heading><tilt>{}</tilt><roll>{}</roll><altitudeMode>absolute</altitudeMode></Camera>'.format(
    TEST_POSE_LAT,
    TEST_POSE_LON,
    TEST_POSE_ALT,
    TEST_POSE_HEADING,
    TEST_POSE_TILT,
    TEST_POSE_ROLL
)


class TestQueryWriter(unittest.TestCase):
    def setUp(self):
        rospy.init_node(NAME)
        self.writer = QueryWriter(TEST_FILE)

    def tearDown(self):
        try:
            os.remove(TEST_FILE)
        except:
            pass

    def test_handle_playtour(self):
        tour = String(TOUR_NAME)
        self.writer.handle_tour(tour)

        expected = 'playtour={}'.format(TOUR_NAME)

        with open(TEST_FILE, 'r') as f:
            content = f.read()
        self.assertEqual(content, expected)

    def test_handle_exittour(self):
        tour = String(EXIT_TOUR)
        self.writer.handle_tour(tour)

        expected = 'exittour='

        with open(TEST_FILE, 'r') as f:
            content = f.read()
        self.assertEqual(content, expected)

    def test_handle_planet(self):
        planet = String(PLANET_NAME)
        self.writer.handle_planet(planet)

        expected = 'planet={}'.format(PLANET_NAME)

        with open(TEST_FILE, 'r') as f:
            content = f.read()
        self.assertEqual(content, expected)

    def test_handle_search(self):
        search = String(SEARCH_QUERY)
        self.writer.handle_search(search)

        expected = 'search={}'.format(SEARCH_QUERY)

        with open(TEST_FILE, 'r') as f:
            content = f.read()
        self.assertEqual(content, expected)

    def test_flyto_kml(self):
        kml = String(FLYTO_KML)
        self.writer.handle_flyto_kml(kml)

        expected = 'flytoview={}'.format(FLYTO_KML)

        with open(TEST_FILE, 'r') as f:
            content = f.read()
        self.assertEqual(content, expected)

    def test_flyto_pose_camera(self):
        pose = Pose()
        pose.position.x = TEST_POSE_LON
        pose.position.y = TEST_POSE_LAT
        pose.position.z = TEST_POSE_ALT
        pose.orientation.x = TEST_POSE_HEADING
        pose.orientation.y = TEST_POSE_TILT
        pose.orientation.z = TEST_POSE_ROLL

        self.writer.handle_flyto_pose_camera(pose)

        with open(TEST_FILE, 'r') as f:
            content = f.read()

        parts = content.split('=')
        self.assertEqual(2, len(parts))
        self.assertEqual('flytoview', parts[0])
        kml = parts[1]
        expected_kml = '<Camera><latitude>{}</latitude><longitude>{}</longitude><altitude>{}</altitude><heading>{}</heading><tilt>{}</tilt><roll>{}</roll><altitudeMode>absolute</altitudeMode></Camera>'.format(
            TEST_POSE_LAT,
            TEST_POSE_LON,
            TEST_POSE_ALT,
            TEST_POSE_HEADING,
            TEST_POSE_TILT,
            TEST_POSE_ROLL
        )

    def test_flyto_pose_lookat(self):
        pose = Pose()
        pose.position.x = TEST_POSE_LON
        pose.position.y = TEST_POSE_LAT
        pose.position.z = TEST_POSE_ALT
        pose.orientation.x = TEST_POSE_HEADING
        pose.orientation.y = TEST_POSE_TILT
        pose.orientation.z = TEST_POSE_RANGE

        self.writer.handle_flyto_pose_lookat(pose)

        with open(TEST_FILE, 'r') as f:
            content = f.read()

        parts = content.split('=')
        self.assertEqual(2, len(parts))<commit_msg>Fix Pose->KML orientation axes in test<commit_after>#!/usr/bin/env python
PKG = 'lg_earth'
NAME = 'test_query_writer'

import rospy
import unittest
import os

from lg_earth import QueryWriter
from std_msgs.msg import String
from geometry_msgs.msg import Pose

TEST_FILE = '/tmp/query_writer_test'
TOUR_NAME = 'Amazonian Village'
EXIT_TOUR = ''
PLANET_NAME = 'mars'
SEARCH_QUERY = '10010'
TEST_POSE_LON = 20
TEST_POSE_LAT = 31.5
TEST_POSE_ALT = 22
TEST_POSE_HEADING = 270
TEST_POSE_TILT = -12
TEST_POSE_ROLL = 0
TEST_POSE_RANGE = 5000
FLYTO_KML = '<Camera><latitude>{}</latitude><longitude>{}</longitude><altitude>{}</altitude><heading>{}</heading><tilt>{}</tilt><roll>{}</roll><altitudeMode>absolute</altitudeMode></Camera>'.format(
    TEST_POSE_LAT,
    TEST_POSE_LON,
    TEST_POSE_ALT,
    TEST_POSE_HEADING,
    TEST_POSE_TILT,
    TEST_POSE_ROLL
)


class TestQueryWriter(unittest.TestCase):
    def setUp(self):
        rospy.init_node(NAME)
        self.writer = QueryWriter(TEST_FILE)

    def tearDown(self):
        try:
            os.remove(TEST_FILE)
        except:
            pass

    def test_handle_playtour(self):
        tour = String(TOUR_NAME)
        self.writer.handle_tour(tour)

        expected = 'playtour={}'.format(TOUR_NAME)

        with open(TEST_FILE, 'r') as f:
            content = f.read()
        self.assertEqual(content, expected)

    def test_handle_exittour(self):
        tour = String(EXIT_TOUR)
        self.writer.handle_tour(tour)

        expected = 'exittour='

        with open(TEST_FILE, 'r') as f:
            content = f.read()
        self.assertEqual(content, expected)

    def test_handle_planet(self):
        planet = String(PLANET_NAME)
        self.writer.handle_planet(planet)

        expected = 'planet={}'.format(PLANET_NAME)

        with open(TEST_FILE, 'r') as f:
            content = f.read()
        self.assertEqual(content, expected)

    def test_handle_search(self):
        search = String(SEARCH_QUERY)
        self.writer.handle_search(search)

        expected = 'search={}'.format(SEARCH_QUERY)

        with open(TEST_FILE, 'r') as f:
            content = f.read()
        self.assertEqual(content, expected)

    def test_flyto_kml(self):
        kml = String(FLYTO_KML)
        self.writer.handle_flyto_kml(kml)

        expected = 'flytoview={}'.format(FLYTO_KML)

        with open(TEST_FILE, 'r') as f:
            content = f.read()
        self.assertEqual(content, expected)

    def test_flyto_pose_camera(self):
        pose = Pose()
        pose.position.x = TEST_POSE_LON
        pose.position.y = TEST_POSE_LAT
        pose.position.z = TEST_POSE_ALT
        pose.orientation.z = TEST_POSE_HEADING
        pose.orientation.x = TEST_POSE_TILT
        pose.orientation.y = TEST_POSE_ROLL

        self.writer.handle_flyto_pose_camera(pose)

        with open(TEST_FILE, 'r') as f:
            content = f.read()

        parts = content.split('=')
        self.assertEqual(2, len(parts))
        self.assertEqual('flytoview', parts[0])
        kml = parts[1]
        expected_kml = '<Camera><latitude>{}</latitude><longitude>{}</longitude><altitude>{}</altitude><heading>{}</heading><tilt>{}</tilt><roll>{}</roll><altitudeMode>absolute</altitudeMode></Camera>'.format(
            TEST_POSE_LAT,
            TEST_POSE_LON,
            TEST_POSE_ALT,
            TEST_POSE_HEADING,
            TEST_POSE_TILT,
            TEST_POSE_ROLL
        )

    def test_flyto_pose_lookat(self):
        pose = Pose()
        pose.position.x = TEST_POSE_LON
        pose.position.y = TEST_POSE_LAT
        pose.position.z = TEST_POSE_ALT
        pose.orientation.z = TEST_POSE_HEADING
        pose.orientation.x = TEST_POSE_TILT
        pose.orientation.y = TEST_POSE_RANGE

        self.writer.handle_flyto_pose_lookat(pose)

        with open(TEST_FILE, 'r') as f:
            content = f.read()

        parts = content.split('=')
        self.assertEqual(2, len(parts))
{'fraction_non_alphanumeric': 0.1175427485750475, 'fraction_numerical': 0.006586447118429386, 'mean_word_length': 2.681118881118881, 'pattern_counts': {'":': 0, '<': 67, '<?xml version=': 0, '>': 68, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '513358', 'n_tokens_mistral': 2769, 'n_tokens_neox': 2653, 'n_words': 438}