コード例 #1
0
ファイル: test_inserts.py プロジェクト: blester125/prehashed
def test_set_default_later_lookup(d):
    key = rand_string()
    value = rand_string()
    res = d.setdefault(key, value)
    assert res == value
    res = d[key]
    assert res == value
コード例 #2
0
ファイル: test_inserts.py プロジェクト: blester125/prehashed
def test_set_default_there(d):
    key = rand_string()
    value = rand_string()
    default = rand_string()
    d[key] = value
    res = d.setdefault(key, default)
    assert res == value
コード例 #3
0
ファイル: test_gets.py プロジェクト: blester125/prehashed
def test_pop_removes(d):
    key = rand_string()
    value = rand_string()
    default = rand_string()
    d[key] = value
    _ = d.pop(key, default)
    assert key not in d
コード例 #4
0
def test_copy_same_keys(d):
    keys = [rand_string() for _ in rand_len()]
    values = [rand_string() for _ in keys]
    d = PrehashedDict(zip(keys, values))
    g = d.copy()
    for k in keys:
        assert k in g
コード例 #5
0
def test_del_present(d):
    key = rand_string()
    value = rand_string()
    d[key] = value
    del d[key]
    with pytest.raises(KeyError):
        res = d[key]
コード例 #6
0
    def test(self):
        r = 'test-repo-' + rand_string()
        r_path = path.join(_repos_dir, r)
        f = 'rep-' + rand_string()
        f_path = path.join(r_path, f)
        c = 'contentsts'
        
        os.mkdir(r_path)
        try:
            fh = open(f_path, 'wb')
            try:
                fh.write(c)
                a = RepositoryFile(repo=r, repo_path=f)
                a.clean()
                a.save()
                
                self.assertEqual(a.path, path.join(_repos_dir, r, f))
                self.assertEqual(urllib.unquote(a.url), _repos_url + r + '/' + f)
                
            finally:
                fh.close()
                os.remove(f_path)
        finally:
            os.rmdir(r_path)

        self.assertEqual(a.specific_instance(), a)
        self.assertEqual(a.document_ptr.__class__, Document)
        self.assertNotEqual(a.document_ptr.__class__, RepositoryFile)
        self.assertEqual(a.document_ptr.specific_instance(), a)
        self.assertEqual(a.document_ptr.specific_instance().__class__, RepositoryFile)
コード例 #7
0
def test_copy_same_values(d):
    keys = [rand_string() for _ in rand_len()]
    values = [rand_string() for _ in keys]
    d = PrehashedDict(zip(keys, values))
    g = d.copy()
    for k, v in zip(keys, values):
        assert g[k] == v
コード例 #8
0
ファイル: test_inserts.py プロジェクト: blester125/prehashed
def test_overwrite(d):
    key = rand_string()
    value = rand_string()
    new_value = rand_string()
    d[key] = value
    assert d[key] == value
    d[key] = new_value
    assert d[key] == new_value
コード例 #9
0
ファイル: test_gets.py プロジェクト: blester125/prehashed
def test_pop_there_default(d):
    key = rand_string()
    value = rand_string()
    default = rand_string()
    d[key] = value
    res = d.pop(key, default)
    assert res != default
    assert res == value
コード例 #10
0
def test_copy_is_shallow(d):
    keys = [rand_string() for _ in rand_len()]
    values = [rand_string() for _ in keys]
    d = PrehashedDict(zip(keys, values))
    d['12'] = [1, 2, 3]
    g = d.copy()
    g['12'].append(4)
    assert d['12'] == [1, 2, 3, 4]
コード例 #11
0
ファイル: test_inserts.py プロジェクト: blester125/prehashed
def test_insert(d):
    key = rand_string()
    value = rand_string()
    d[key] = value
    assert key in d
    assert super(PrehashedDict, d).__contains__(sha1_fn(key))
    assert d[key] == value
    assert super(PrehashedDict, d).__getitem__(sha1_fn(key))
コード例 #12
0
def test_copy_delete_one_old(d):
    keys = [rand_string() for _ in rand_len()]
    values = [rand_string() for _ in keys]
    d = PrehashedDict(zip(keys, values))
    g = d.copy()
    del_key = random.choice(keys)
    del d[del_key]
    assert del_key in g
    assert del_key not in d
コード例 #13
0
def test_copy_change_one_old(d):
    keys = [rand_string() for _ in rand_len()]
    values = [rand_string() for _ in keys]
    d = PrehashedDict(zip(keys, values))
    g = d.copy()
    new_val = rand_string()
    changed_key = random.choice(keys)
    d[changed_key] = new_val
    assert d[changed_key] == new_val
    assert g[changed_key] != new_val
コード例 #14
0
ファイル: test_inserts.py プロジェクト: blester125/prehashed
def test_initial_add():
    key = rand_string()
    value = rand_string()
    new_value = rand_string()
    d = PrehashedDict(((key, value), ))
    new_key = d.initial_add(key, new_value)
    assert d[new_key] == new_value
    assert d[key] == value
    assert key != new_key
    assert len(new_key) > len(key)
コード例 #15
0
def test_copy_add_one_old(d):
    keys = [rand_string() for _ in rand_len()]
    values = [rand_string() for _ in keys]
    d = PrehashedDict(zip(keys, values))
    g = d.copy()
    new_key = rand_string()
    new_val = rand_string()
    d[new_key] = new_val
    assert d[new_key] == new_val
    assert new_key in d
    assert new_key not in g
コード例 #16
0
ファイル: test_create.py プロジェクト: blester125/prehashed
def test_pickle(file_cleanup):
    file_name = file_cleanup
    keys = [rand_string() for _ in rand_len()]
    vals = [rand_string() for _ in keys]
    d = PrehashedDict({k: v for k, v in zip(keys, vals)})
    pickle.dump(d, open(file_name, 'wb'))
    d1 = pickle.load(open(file_name, 'rb'))
    for k in keys:
        assert k in d
        assert k in d1
    for k, v in zip(keys, vals):
        assert d1[k] == v
    assert d == d1
コード例 #17
0
ファイル: test_create.py プロジェクト: blester125/prehashed
def test_init_calls_process_args():
    d = PrehashedDict({rand_string(): rand_string()})
    with patch('prehashed.prehashed.PrehashedDict._process_args') as mock:
        arg = random.choice([{
            rand_string(): rand_string()
        }, ((rand_string(), rand_string())), (), d])
        kwargs = {rand_string(): rand_string() for _ in rand_len(0, 2)}
        d = PrehashedDict(arg, **kwargs)
        mock.assert_called_once_with(arg, **kwargs)
コード例 #18
0
ファイル: watcher.py プロジェクト: lxrave/pywebmastertool
 def _make_pdf(self):
     colored_print('Generating PDFs...', 'OKGREEN')
     html_files = glob.glob(os.path.join(self.html_output, '*.html'))
     for html_file in html_files:
         pdf_filename = os.path.splitext(ntpath.basename(html_file))[0]
         pdf_filename += rand_string(5)
         pdf_filename += '.pdf'
         try:
             HTML(html_file).write_pdf(os.path.join(self.pdf_output, pdf_filename), zoom=1.75)
         except Exception as e:
             colored_print('PDF `%s` generation failed' % pdf_filename, 'FAIL')
コード例 #19
0
 def test_sign_verify(self):
     key = crypto.ZilKey.generate_new()
     for i in range(10):
         l = 1 + i * 512
         msg = utils.rand_bytes(l) + utils.rand_string(l).encode()
         signature = key.sign(msg)
         assert isinstance(signature, bytes)
         assert key.verify(signature, msg)
         signature_str = key.sign_str(msg)
         assert isinstance(signature_str, str)
         assert key.verify(signature_str, msg)
コード例 #20
0
 def test_fs(self):
     test_filename = 'test-' + rand_string()
     
     contents = 'contestns'
     
     fs.save(test_filename, ContentFile(contents))
     self.assertEqual(fs.exists(test_filename), True)
     self.assertEqual(fs.size(test_filename), len(contents))
     self.assertEqual(fs.open(test_filename).read(), contents)
     
     fs.delete(test_filename)
     self.assertEqual(fs.exists(test_filename), False)
コード例 #21
0
ファイル: watcher.py プロジェクト: lxrave/pywebmastertool
 def _compile_sass(self):
     colored_print('Recompiling SaSS... ', 'OKGREEN')
     css_filename = os.path.join(self.html_css, 'main.' + rand_string(12) + '.css')
     try:
         compiled = sass.compile(
             filename=os.path.join(self.sass, 'main.scss'),
             output_style='compressed'
         )
         with open(css_filename, 'w') as f:
             f.write(compiled)
     except Exception as e:
         colored_print(e, 'WARNING')
     return css_filename
コード例 #22
0
    def test(self):
        filename = 'up-' + rand_string()
        contents = 'upladded contestsn'
    
        a = UploadedFile(
            uploader = self.test_user,
        )
        a.uploaded_file.save(filename, ContentFile(contents))
        a.clean()
        a.save()

        # TODO self.assertEqual(a.url,?)
        # TODO self.assertEqual(a.path,?)

        self.assertEqual(a.specific_instance(), a)
        self.assertEqual(a.document_ptr.__class__, Document)
        self.assertNotEqual(a.document_ptr.__class__, UploadedFile)
        self.assertEqual(a.document_ptr.specific_instance(), a)
        self.assertEqual(a.document_ptr.specific_instance().__class__, UploadedFile)
コード例 #23
0
ファイル: waver1.py プロジェクト: deniskolokol/term_visual
# -*- coding: utf-8 -*-

import os
import time
import random
from utils import shoot, random, spinning_cursor, rand_string, weighted_choice

i = 0
curr = 0
while True:
    disp = int((curr + random.uniform(1, 35)) / 2.)  # smooth it out
    curr = disp

    attrs = None if disp > 25 else ['dark']

    shoot('{0: <35}'.format("|" * disp), 'white', attrs=attrs)
    time.sleep(random.random() * 0.1)
    i += 1

    # occasionally clear the screen and output rand string
    if i >= 100:
        if weighted_choice([(True, 1), (False, 9)]):
            os.system('clear')
            shoot("\n%s\n" % rand_string(random.randint(200, 800)),
                  color='red')
            spinning_cursor(random.random() * 0.5)
        i = 0
コード例 #24
0
ファイル: test_gets.py プロジェクト: blester125/prehashed
def test_pop_not_there_default(d):
    key = rand_string()
    default = rand_string()
    res = d.pop(key, default)
    assert res == default
コード例 #25
0
def test_sha1_type():
    key = rand_string()
    assert isinstance(sha1_fn(key), int)
コード例 #26
0
ファイル: test_gets.py プロジェクト: blester125/prehashed
def test_pop_not_there_no_default(d):
    key = rand_string()
    with pytest.raises(KeyError):
        d.pop(key)
コード例 #27
0
ファイル: test_create.py プロジェクト: blester125/prehashed
def test_from_keys_value(d):
    keys = [rand_string() for _ in rand_len()]
    value = rand_string()
    d = PrehashedDict.fromkeys(keys, value)
    for k in keys:
        assert d[k] == value
コード例 #28
0
ファイル: test_create.py プロジェクト: blester125/prehashed
def test_from_keys():
    keys = [rand_string() for _ in rand_len()]
    d = PrehashedDict.fromkeys(keys)
    for k in keys:
        assert d[k] == None
コード例 #29
0
ファイル: test_create.py プロジェクト: blester125/prehashed
def test_process_args_iterable_kwargs(d):
    kwargs = {rand_string(): rand_string() for _ in rand_len()}
    it = [(rand_string(), rand_string()) for _ in rand_len()]
    res = list(d._process_args(it, **kwargs))
    assert find(it, res)
    assert find(kwargs.items(), res)
コード例 #30
0
ファイル: test_create.py プロジェクト: blester125/prehashed
def test_process_args_iterable(d):
    it = [(rand_string(), rand_string()) for _ in rand_len()]
    res = list(d._process_args(it))
    assert find(it, res)
コード例 #31
0
ファイル: test_create.py プロジェクト: blester125/prehashed
def test_process_args_prehased_kwargs(d):
    d1 = PrehashedDict({rand_string(): rand_string() for _ in rand_len()})
    kwargs = {rand_string(): rand_string() for _ in rand_len()}
    res = list(d._process_args(d1, **kwargs))
    assert find(d1.items(), res, hash_me=False)
    assert find(kwargs.items(), res)
コード例 #32
0
ファイル: test_create.py プロジェクト: blester125/prehashed
def test_process_args_dict_kwargs(d):
    dic = {rand_string(): rand_string() for _ in rand_len()}
    kwargs = {rand_string(): rand_string() for _ in rand_len()}
    res = list(d._process_args(dic, **kwargs))
    assert find(dic.items(), res)
    assert find(kwargs.items(), res)
コード例 #33
0
ファイル: test_create.py プロジェクト: blester125/prehashed
def test_process_args_kwargs(d):
    kwargs = {rand_string(): rand_string() for _ in rand_len()}
    print(kwargs)
    res = list(d._process_args(**kwargs))
    assert find(kwargs.items(), res)