<commit_before>#! /usr/bin/env python
'''
Copyright (C) 2014 <NAME>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
'''

import sys
import os
import getopt
import unittest

try:
    sys.path.append(os.path.join(os.environ['ANDROID_VIEW_CLIENT_HOME'], 'src'))
except:
    pass

from com.dtmilano.android.viewclient import ViewClient

class YkspTestCase(unittest.TestCase):

    package = None

    serial = None

    dirRoot = None

    logsFilename = None

    screenshotFolder = None

    screendumpFolder = None

    screenCount = 0

    def setUp(self):
        # Connnect to device
        self.device, self.serialno = ViewClient.connectToDeviceOrExit(serialno=YkspTestCase.serial)

        # Wake device
        self.device.wake()

        # Create ViewClient instance
        self.vc = ViewClient(self.device, self.serialno)

    def tearDown(self):
        # Force-stop the app
        self.device.shell('am force-stop %s' % YkspTestCase.package)

    def startActivity(self, activity, package=None):
        '''
        Starts an Activity.

        @type activity: str
        @param activity: The name of the Android Activity.
        @type package: str
        @param package: An optional parameter to indicate the package name of the Activity. If not provided, the application package name specified in the application manifest is used.
        '''
        if package is None:
            package = YkspTestCase.package

        component = '%s/.%s' % (package, activity)
        try:
            self.device.startActivity(component)
        except RuntimeError:
            self.fail('Failed to start %s' % component)

    def saveScreen(self, tag=None, sleep=0):
        '''
        Saves to disk the screenshot and screendump of the device screen.

        @type tag: str
        @param tag: The tag for this screen. This is appended to the filenames.
        @type sleep: float
        @param sleep: An optional parameter to indicate the time to sleep before saving the screen. Defaults to zero.
        '''
        if sleep > 0:<commit_msg>Missed file in the previous commit<commit_after>#! /usr/bin/env python
'''
Copyright (C) 2014 <NAME>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
'''

import sys
import os
import getopt
import unittest

try:
    sys.path.append(os.path.join(os.environ['ANDROID_VIEW_CLIENT_HOME'], 'src'))
except:
    pass

from com.dtmilano.android.viewclient import ViewClient

class YkspTestCase(unittest.TestCase):

    package = None

    serial = None

    dirRoot = None

    logsFilename = None

    screenshotFolder = None

    screendumpFolder = None

    screenCount = 0

    def setUp(self):
        # Connnect to device
        self.device, self.serialno = ViewClient.connectToDeviceOrExit(serialno=YkspTestCase.serial)

        # Wake device
        self.device.wake()

        # Create ViewClient instance
        self.vc = ViewClient(self.device, self.serialno, autodump=False)

    def tearDown(self):
        # Force-stop the app
        self.device.shell('am force-stop %s' % YkspTestCase.package)

    def launchApp(self, package=None):
        '''
        Launches an app as if from the launcher.

        @type package: str
        @param package: An optional parameter to specify an application to launch by its package name. If not provided, the application package name provided in the application manifest is used.
        '''
        if package is None:
            package = YkspTestCase.package
        self.device.shell('monkey -p %s -c android.intent.category.LAUNCHER 1' % package)

    def refreshScreen(self, sleep=1):
        '''
        Updates the view tree. This method or saveScreen() must be called after each screen transition to keep the view tree in sync with the device screen.

        @type sleep: float
        @param sleep: An optional parameter to indicate the time to sleep before refreshing the screen. Defaults to one second.
        '''
        self.vc.dump(window=-1, sleep=sleep)

    def saveScreen(self, tag=None, sleep=1):
        '''
        Updates the view tree and saves to disk the screenshot and screendump of the device screen. This method or refreshScreen() must be called after each screen transition to keep the view tree in sync with the device screen.

        @type tag: str
        @param tag: The tag for this screen. This is appended to the filename.
        @type sleep: float
        @param sleep: An optional parameter to indicate the time to sleep before saving the screen. Defaults to one second.
        '''
        if sleep > 0:
{'fraction_non_alphanumeric': 0.07385229540918163, 'fraction_numerical': 0.004536381781890764, 'mean_word_length': 2.835768963117606, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4361907', 'n_tokens_mistral': 1508, 'n_tokens_neox': 1447, 'n_words': 607}