示例#1
0
def doclet_full_path(d, base_dir, longname_field='longname'):
    """Return the full, unambiguous list of path segments that points to an
    entity described by a doclet.

    Example: ``['./', 'dir/', 'dir/', 'file/', 'object.', 'object#', 'object']``

    :arg d: The doclet
    :arg base_dir: Absolutized value of the jsdoc_source_path option
    :arg longname_field: The field to look in at the top level of the doclet
        for the long name of the object to emit a path to
    """
    meta = d['meta']
    path = meta['path']
    if platform.upper() == 'CYGWIN':
        # Check if path is absolute Windows style path
        if path[1:3] == ':\\':
            import ntpath
            pathArray = path.split(ntpath.sep)
            pathArray[0] = '/cygdrive/%s' % pathArray[0][0].lower()	# Keep drive letter
            path = join(*pathArray);
    rel = relpath(path, base_dir)
    if not rel.startswith(('../', './')) and rel not in ('..', '.'):
        # It just starts right out with the name of a folder in the cwd.
        rooted_rel = './%s' % rel
    else:
        rooted_rel = rel

    # Building up a string and then parsing it back down again is probably
    # not the fastest approach, but it means knowledge of path format is in
    # one place: the parser.
    path = '%s/%s:%s' % (rooted_rel,
                         splitext(meta['filename'])[0],
                         d[longname_field])
    return PathVisitor().visit(
        path_and_formal_params['path'].parse(path))
示例#2
0
    def test_NBeats(self):
        # NBeats based model
        lookback = 12
        exo_ins = 81
        forecsat_length = 4  # predict next 4 values
        layers = {
            "Input": {
                "config": {
                    "shape": (lookback, 1),
                    "name": "prev_inputs"
                }
            },
            "Input_Exo": {
                "config": {
                    "shape": (lookback, exo_ins),
                    "name": "exo_inputs"
                }
            },
            "NBeats": {
                "config": {
                    "backcast_length": lookback,
                    "input_dim": 1,
                    "exo_dim": exo_ins,
                    "forecast_length": forecsat_length,
                    "stack_types": ('generic', 'generic'),
                    "nb_blocks_per_stack": 2,
                    "thetas_dim": (4, 4),
                    "share_weights_in_stack": True,
                    "hidden_layer_units": 62
                },
                "inputs": "prev_inputs",
                "call_args": {
                    "exo_inputs": "exo_inputs"
                }
            },
            "Flatten": {
                "config": {}
            },
            "Reshape": {
                "config": {
                    "target_shape": (1, forecsat_length)
                }
            }
        }

        predictions = make_and_run(NBeatsModel,
                                   layers=layers,
                                   forecast_length=forecsat_length,
                                   data_type="nasdaq")
        if platform.upper() in ["WIN32"]:
            self.assertAlmostEqual(float(predictions.sum()), 780624765.5024414,
                                   4)
        else:
            self.assertGreater(float(predictions.sum()),
                               80000.0)  # TODO reproduction failing on linux
def set_wallpaper(file_path):
    if SHOW_DEBUG:
        print "Setting the wallpaper"

    if platform.upper() == 'DARWIN':
        osa_command = ('tell application "Finder" to set desktop picture to POSIX file "{:s}"'.format(os.path.realpath(file_path)))
        command = ['osascript', '-e', osa_command]
        subprocess.check_call(command)
    else:
        command = "gsettings set org.gnome.desktop.background picture-uri file://" + file_path
        status, output = commands.getstatusoutput(command)
 def set_driver(self):
     """This method sets the driver the driver -- Should only be used by go_to_url(browser) method
     """
     if self.driver_type is None:
         self.driver_type = "firefox"
         warning("Browser not defined, using default: 'Firefox'")
         warning("Use set_browser_type(browser_name) to properly set the browser")
     if self.driver is None:
         if self.driver_type.upper() == "firefox".upper():
             self.driver = webdriver.Firefox()
         elif self.driver_type.upper() == "chrome".upper():
             try:
                 self.driver = webdriver.Chrome()
             except WebDriverException as e:
                 fail(e)
         elif self.driver_type.upper() == "iexplorer".upper():
             try:
                 self.driver = webdriver.Ie()
             except WebDriverException as e:
                 fail(e)
         elif self.driver_type.upper() == "edge".upper():
             try:
                 self.driver = webdriver.Edge()
             except WebDriverException as e:
                 fail(e)
         elif self.driver_type.upper() == "safari".upper():
             if platform.upper() is "Darwin".upper():
                 try:
                     self.driver = webdriver.Safari()
                 except WebDriverException as e:
                     fail(e)
             else:
                 fail("Safari browser is only supported on Mac OS")
         elif self.driver_type.upper() == "AppiumChrome".upper():
             self.desired_caps = {
                 "platformName": "Android",
                 "platformVersion": "4.4",
                 "deviceName": "motorola-nexus_6-ZX1G424TK3",
                 "browserName": "Chrome",
                 "app": "Chrome",
             }
             log("Opening Driver")
             return webdriver.Remote("http://localhost:4723/wd/hub", self.desired_caps)
         else:
             # ToDo Error implementation
             fail(
                 "Browser not defined, the only available values are: 'firefox', 'chrome', 'safari', 'iexplorer' "
                 "and 'edge'"
             )
             # raise BrowserNotDefined
     self.setup_driver()
     self.multi_driver.append(self.driver)
     return self.driver
示例#5
0
    def to_str3(bytes_or_str):
        """
        把byte类型转换为str
        :param bytes_or_str: bytes数据
        :return: 返回字符串
        """
        if isinstance(bytes_or_str, bytes):
            if 'linux'.upper() in platform.upper():
                value = bytes_or_str.decode('utf-8')
            elif ('window' in platform) or ('win32' == platform):
                value = bytes_or_str.decode('gbk')
            else:
                value = bytes_or_str
        else:
            value = bytes_or_str

        return value