Example #1
0
 def test_next(self):
     datafile = 'examples/data/colors.txt'
     seed_value = 123
     r = RanCat(seed=seed_value)
     r.load(datafile)
     value = r.next()
     assert isinstance(value, str)
Example #2
0
 def test_next(self):
     datafile = 'examples/data/colors.txt'
     seed_value = 123
     r = RanCat(seed=seed_value)
     r.load(datafile)
     value = r.next()
     assert isinstance(value, str)
Example #3
0
 def test_duplicate_file_allowed(self):
     datafile = 'examples/data/colors.txt'
     seed_value = 123
     r = RanCat(seed=seed_value)
     r.load(datafile).load(datafile).load(datafile)
     result = r.next()
     result = result.split('_')
     assert len(result) == 3
Example #4
0
 def test_duplicate_file_allowed(self):
     datafile = 'examples/data/colors.txt'
     seed_value = 123
     r = RanCat(seed=seed_value)
     r.load(datafile).load(datafile).load(datafile)
     result = r.next()
     result = result.split('_')
     assert len(result) == 3
Example #5
0
 def test_iterable(self):
     datafile = 'examples/data/colors.txt'
     seed_value = 123
     r = RanCat(seed=seed_value)
     r.load(datafile)
     i = []
     for x in r:
         i.append(x)
         break
     assert i != []
Example #6
0
 def test_iterable(self):
     datafile = 'examples/data/colors.txt'
     seed_value = 123
     r = RanCat(seed=seed_value)
     r.load(datafile)
     i = []
     for x in r:
         i.append(x)
         break
     assert i != []
Example #7
0
 def test_unique_option(self):
     datafile = 'examples/data/colors.txt'
     seed_value = 123
     r = RanCat(seed=seed_value)
     r.set_unique(True)
     r.load(datafile)
     i = []
     for x in r:
         i.append(x)
     assert i != []
     assert len(i) == r._total_combinations
Example #8
0
 def test_read_size_option(self):
     datafile = 'examples/data/colors.txt'
     seed_value = 123
     r = RanCat(seed=seed_value)
     r.set_read_size(2)
     r.load(datafile)
     r._refresh_all(r._read_size)
     assert len(r.files[datafile].current_lines) == 2
Example #9
0
 def test_init_with_seed(self):
     seed_value = 123
     r = RanCat(seed=seed_value)
     assert len(r.files) == 0
     assert not hasattr(r.seed, '__call__')
     assert r.seed == seed_value
     assert hasattr(r._conversion, '__call__')
Example #10
0
    def test_hard_reset(self):
        datafile = 'examples/data/colors.txt'
        seed_value = 123
        r = RanCat(seed=seed_value, unique=True)
        r.load(datafile).load(datafile)
        i = []
        for x in r:
            i.append(x)
        assert i != []
        assert len(i) == r._total_combinations

        r = r.hard_reset()
        i = []
        for x in r:
            i.append(x)
        assert i == []
        assert len(r.files) == 0
        assert len(i) == r._total_combinations
Example #11
0
    def test_hard_reset(self):
        datafile = 'examples/data/colors.txt'
        seed_value = 123
        r = RanCat(seed=seed_value, unique=True)
        r.load(datafile).load(datafile)
        i = []
        for x in r:
            i.append(x)
        assert i != []
        assert len(i) == r._total_combinations

        r = r.hard_reset()
        i = []
        for x in r:
            i.append(x)
        assert i == []
        assert len(r.files) == 0
        assert len(i) == r._total_combinations
Example #12
0
 def test_read_size_option(self):
     datafile = 'examples/data/colors.txt'
     seed_value = 123
     r = RanCat(seed=seed_value)
     r.set_read_size(2)
     r.load(datafile)
     r._refresh_all(r._read_size)
     assert len(r.files[datafile].current_lines) == 2
Example #13
0
    def test_set_conversion(self):
        raw_string = 'string'
        correct_string = raw_string.upper()
        r = RanCat()
        r.set_conversion(str.upper)
        processed_string = r._conversion(raw_string)
        assert processed_string == correct_string

        # Test TypeError gets raised
        with pytest.raises(TypeError):
            r.set_conversion("hello")
Example #14
0
    def test_set_conversion(self):
        raw_string = 'string'
        correct_string = raw_string.upper()
        r = RanCat()
        r.set_conversion(str.upper)
        processed_string = r._conversion(raw_string)
        assert processed_string == correct_string

        # Test TypeError gets raised
        with pytest.raises(TypeError):
            r.set_conversion("hello")
Example #15
0
 def test_unique_option(self):
     datafile = 'examples/data/colors.txt'
     seed_value = 123
     r = RanCat(seed=seed_value)
     r.set_unique(True)
     r.load(datafile)
     i = []
     for x in r:
         i.append(x)
     assert i != []
     assert len(i) == r._total_combinations
Example #16
0
 def test_default_conversion(self):
     raw_string = 'S\'tr ing   '
     correct_string = 'Str_ing'
     r = RanCat()
     processed_string = r._conversion(raw_string, r._separator)
     assert processed_string == correct_string
Example #17
0
 def test_load_structure(self):
     datafile = 'examples/data/colors.txt'
     r = RanCat().load_structure(datafile, ['cat', 'dog'])
     phrase = r.next()
     assert phrase.endswith('cat') or phrase.endswith('dog')
Example #18
0
 def test_load_url(self):
     data_url = 'http://www.sample-videos.com/text/Sample-text-file-10kb.txt'
     seed_value = 123
     r = RanCat(seed=seed_value)
     r.load(data_url)
     assert len(r.files) == 1
Example #19
0
 def test_load(self):
     datafile = 'examples/data/colors.txt'
     seed_value = 123
     r = RanCat(seed=seed_value)
     r.load(datafile)
     assert len(r.files) == 1
Example #20
0
 def test_default_input(self):
     r = RanCat()
     r.load_default()
     r.load_default()
     assert r.next() != ''
Example #21
0
 def test_default_conversion(self):
     raw_string = 'S\'tr ing   '
     correct_string = 'Str_ing'
     r = RanCat()
     processed_string = r._conversion(raw_string, r._separator)
     assert processed_string == correct_string
Example #22
0
 def test_load_structure(self):
     datafile = 'examples/data/colors.txt'
     r = RanCat().load_structure(datafile, ['cat', 'dog'])
     phrase = r.next()
     assert phrase.endswith('cat') or phrase.endswith('dog')
Example #23
0
 def test_set_separator(self):
     r = RanCat()
     assert r._separator == '_'
     r.set_separator('-')
     assert r._separator == '-'
Example #24
0
 def test_default_input(self):
     r = RanCat()
     r.load_default()
     r.load_default()
     assert r.next() != ''
Example #25
0
 def test_init_without_seed(self):
     r = RanCat()
     assert len(r.files) == 0
     assert not hasattr(r.seed, '__call__')
     assert hasattr(r._conversion, '__call__')
Example #26
0
 def test_load(self):
     datafile = 'examples/data/colors.txt'
     seed_value = 123
     r = RanCat(seed=seed_value)
     r.load(datafile)
     assert len(r.files) == 1
Example #27
0
# Example 2 - Generate phrases from iterables
from rancat import RanCat

r = RanCat(seed=12335)
r.load_structure(['the'], ['cat', 'dog'], ['was'], ['black', 'brown'])
print(r.next())
Example #28
0
 def test_command_chaining(self):
     datafile = 'examples/data/colors.txt'
     r = RanCat().load(datafile).set_unique(True).set_conversion(
         str.upper).set_read_size(100)
     assert isinstance(r, RanCat)
Example #29
0
 def test_set_separator(self):
     r = RanCat()
     assert r._separator == '_'
     r.set_separator('-')
     assert r._separator == '-'
Example #30
0
# Example 1 - Generate names from files
from rancat import RanCat

r = RanCat(seed=12335).load('examples/data/jedi.txt')
r.load('examples/data/got.txt')
for i in range(0, 10):
    print(r.next())
Example #31
0
 def test_load_url(self):
     data_url = 'http://www.sample-videos.com/text/Sample-text-file-10kb.txt'
     seed_value = 123
     r = RanCat(seed=seed_value)
     r.load(data_url)
     assert len(r.files) == 1