예제 #1
0
def test_json_serialization():
    # on windows, we can't open a file twice, so save the name and unlink
    # manually...
    try:
        name = None
        with tempfile.NamedTemporaryFile(delete=False) as temp:
            name = temp.name
        json_dump(fontManager, name)
        copy = json_load(name)
    finally:
        if name and os.path.exists(name):
            os.remove(name)
    with warnings.catch_warnings():
        warnings.filterwarnings('ignore', 'findfont: Font family.*not found')
        for prop in ({
                'family': 'STIXGeneral'
        }, {
                'family': 'Bitstream Vera Sans',
                'weight': 700
        }, {
                'family': 'no such font family'
        }):
            fp = FontProperties(**prop)
            assert (fontManager.findfont(
                fp, rebuild_if_missing=False) == copy.findfont(
                    fp, rebuild_if_missing=False))
예제 #2
0
def test_json_serialization():
    with tempfile.NamedTemporaryFile() as temp:
        json_dump(fontManager, temp.name)
        copy = json_load(temp.name)
    with warnings.catch_warnings():
        warnings.filterwarnings('ignore', 'findfont: Font family.*not found')
        for prop in ({'family': 'STIXGeneral'},
                     {'family': 'Bitstream Vera Sans', 'weight': 700},
                     {'family': 'no such font family'}):
            fp = FontProperties(**prop)
            assert_equal(fontManager.findfont(fp, rebuild_if_missing=False),
                         copy.findfont(fp, rebuild_if_missing=False))
예제 #3
0
def test_json_serialization(tmpdir):
    # Can't open a NamedTemporaryFile twice on Windows, so use a temporary
    # directory instead.
    path = Path(tmpdir, "fontlist.json")
    json_dump(fontManager, path)
    copy = json_load(path)
    with warnings.catch_warnings():
        warnings.filterwarnings('ignore', 'findfont: Font family.*not found')
        for prop in ({'family': 'STIXGeneral'},
                     {'family': 'Bitstream Vera Sans', 'weight': 700},
                     {'family': 'no such font family'}):
            fp = FontProperties(**prop)
            assert (fontManager.findfont(fp, rebuild_if_missing=False) ==
                    copy.findfont(fp, rebuild_if_missing=False))
예제 #4
0
def test_json_serialization(tmpdir):
    # Can't open a NamedTemporaryFile twice on Windows, so use a temporary
    # directory instead.
    path = Path(tmpdir, "fontlist.json")
    json_dump(fontManager, path)
    copy = json_load(path)
    with warnings.catch_warnings():
        warnings.filterwarnings('ignore', 'findfont: Font family.*not found')
        for prop in ({'family': 'STIXGeneral'},
                     {'family': 'Bitstream Vera Sans', 'weight': 700},
                     {'family': 'no such font family'}):
            fp = FontProperties(**prop)
            assert (fontManager.findfont(fp, rebuild_if_missing=False) ==
                    copy.findfont(fp, rebuild_if_missing=False))
예제 #5
0
def test_json_serialization():
    with tempfile.NamedTemporaryFile() as temp:
        json_dump(fontManager, temp.name)
        copy = json_load(temp.name)
    with warnings.catch_warnings():
        warnings.filterwarnings('ignore', 'findfont: Font family.*not found')
        for prop in ({
                'family': 'STIXGeneral'
        }, {
                'family': 'Bitstream Vera Sans',
                'weight': 700
        }, {
                'family': 'no such font family'
        }):
            fp = FontProperties(**prop)
            assert_equal(fontManager.findfont(fp, rebuild_if_missing=False),
                         copy.findfont(fp, rebuild_if_missing=False))
예제 #6
0
def test_json_serialization():
    # on windows, we can't open a file twice, so save the name and unlink
    # manually...
    try:
        name = None
        with tempfile.NamedTemporaryFile(delete=False) as temp:
            name = temp.name
        json_dump(fontManager, name)
        copy = json_load(name)
    finally:
        if name and os.path.exists(name):
            os.remove(name)
    with warnings.catch_warnings():
        warnings.filterwarnings('ignore', 'findfont: Font family.*not found')
        for prop in ({'family': 'STIXGeneral'},
                     {'family': 'Bitstream Vera Sans', 'weight': 700},
                     {'family': 'no such font family'}):
            fp = FontProperties(**prop)
            assert (fontManager.findfont(fp, rebuild_if_missing=False) ==
                    copy.findfont(fp, rebuild_if_missing=False))
예제 #7
0
파일: views.py 프로젝트: mes-src/rebalance
    def write_to_json_for_ajax():
        ''' write values to json files used to populate jquery datatables via ajax '''

        # collect paths to json file for each datatable
        #TODO: os.listdir to read files in directory
        fp1 = os.path.join(cwd, 'equity_fundamentals', 'static', 'forAjax',
                           'opperations.json')
        fp2 = os.path.join(cwd, 'equity_fundamentals', 'static', 'forAjax',
                           'adjustments.json')
        fp3 = os.path.join(cwd, 'equity_fundamentals', 'static', 'forAjax',
                           'fcfgrowth.json')
        fp4 = os.path.join(cwd, 'equity_fundamentals', 'static', 'forAjax',
                           'wacc.json')
        # fp4 = os.path.join(cwd, 'equity_fundamentals', 'static', 'forAjax', 'wacc.json')
        fp5 = os.path.join(cwd, 'equity_fundamentals', 'static', 'forAjax',
                           'expenses.json')

        # iterate through each file that needs to be writen to
        for fp in [fp1, fp2, fp3, fp4, fp5]:
            with open(fp, 'r') as f:
                data = json.load(f)

            # build dictionary with keys == date and values == pd.series of fundamental equity data for that specific date
            fundamentals_dict = {}
            for date in qtr_end_dates[-5:]:
                fundamentals_dict[date] = ndq_data.loc[ndq_data.calendardate ==
                                                       date]

            # iterate through each dictionary item and write values to the desired node of the json file
            ajax_labels = [
                'y-4',
                'y-3',
                'y-2',
                'y-1',
                'y',
            ]
            ajax_delta_labels = [
                'delta5', 'delta4', 'delta3', 'delta2', 'delta1'
            ]
            for i in range(len(data['data'])):
                source_name = data['data'][i].get('source_name')
                for ix, label in enumerate(ajax_labels):
                    if source_name != '':
                        data['data'][i][label] = "{:,.4f}".format(
                            list(fundamentals_dict.values())[ix]
                            [source_name].iloc[0])
                    else:
                        data['data'][i][label] = "None"

                for ix, label in enumerate(ajax_delta_labels):
                    if label != 'delta5':
                        try:
                            data['data'][i][label] = "{:.2%}".format(
                                (list(fundamentals_dict.values())[ix]
                                 [source_name].iloc[0] -
                                 list(fundamentals_dict.values())[
                                     ix - 1][source_name].iloc[0]) /
                                list(fundamentals_dict.values())[
                                    ix - 1][source_name].iloc[0])
                        except KeyError as e:
                            pass
            json_dump(data, fp)