def register_global_var():
    """

    :return:
    """

    path = os.path.expanduser('~/.bash_profile')

    with open(path, 'r+') as f:
        lines = f.read().split('\n')

    entry = 'export TRACKSIM_HOME="{}"'.format(
        paths.project()
    )

    found_existing = False
    for index in range(len(lines)):
        l = lines[index]
        if l.startswith('export TRACKSIM_HOME='):
            if l == entry:
                return

            found_existing = True
            lines[index] = entry
            break

    if not found_existing:
        if len(lines[-1].strip()) < 1:
            lines.append('')
        lines.append('# Added by Tracksim gait analysis command')
        lines.append(entry)

    with open(path, 'w+') as f:
        f.write('\n'.join(lines))
def execute_command():

    source = paths.resource('tracksim.global.sh')

    with open(source, 'r+') as f:
        contents = f.read()

    path = paths.project('bin', 'tracksim')
    contents = contents.replace('###TRACKSIM_PATH###', path)

    path = '/usr/local/bin/tracksim'
    with open(path, 'w+') as f:
        f.write(contents)

    os.chmod(
        path,
        stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR |
        stat.S_IRGRP | stat.S_IWGRP | stat.S_IXGRP |
        stat.S_IROTH | stat.S_IXOTH
    )

    register_global_var()

    system.log("""
        [SUCCESS]: The tracksim command has been registered for global use. You
        can now call tracksim globally from a terminal.

        If you have trouble calling tracksim, make sure you have exported
            /usr/local/bin
        in your .bash_profile PATH.
        """)
    def test_project_path(self):
        """
            Tests making project paths
        """

        # Without arguments
        project_root_path = os.path.abspath(os.path.join(
            MY_DIRECTORY, '..', '..'
        ))
        self.assertEqual(project_root_path, paths.project())

        # With arguments
        self.assertEqual(
            MY_PATH,
            paths.project('tracksim', 'tests', 'test_tracksim.py')
        )
    def test_load_invalid(self):
        """
        """
        path = paths.project('tests', 'resources', 'invalid.json')
        mm_end = mock.MagicMock(name='end')
        system.end = mm_end

        configs.load('trial', path)
        mm_end.assert_called_once_with(1)
    def test_load_missing(self):
        """
        """
        path = paths.project('does_not_exist.fake')
        mm_end = mock.MagicMock(name='end')
        system.end = mm_end

        configs.load('trial', path)
        mm_end.assert_called_once_with(1)
    def test_load_pes_only_file(self):
        """
        """

        path = paths.project('test_resources', 'pes_only_test_data.csv')

        positions = trackway.load_positions_file(path)
        self.assertEqual(len(positions.left_manus), 4)
        self.assertEqual(len(positions.right_manus), 5)
        self.assertEqual(len(positions.left_pes), 4)
        self.assertEqual(len(positions.right_pes), 5)
    def test_load_positions_file(self):
        """
        """

        path = paths.project('test_resources', 'test_data.csv')
        positions = trackway.load_positions_file(path)
        self.assertEqual(len(positions.left_manus), 18)
        self.assertEqual(len(positions.right_manus), 20)
        self.assertEqual(len(positions.left_pes), 21)
        self.assertEqual(len(positions.right_pes), 21)

        result = positions.left_pes[0].echo()
        self.assertIsNotNone(result)