def test_main_infile_stdin(self, argv_handler, capsys):
     # main() also accepts input from stdin
     sys.stdin = StringIO("word1\n")
     sys.argv = ['diceware', '-n', '2', '-']
     main()
     out, err = capsys.readouterr()
     assert out == 'Word1Word1\n'
Exemple #2
0
 def test_main_infile_stdin(self, argv_handler, capsys):
     # main() also accepts input from stdin
     sys.stdin = StringIO("word1\n")
     sys.argv = ['diceware', '-n', '2', '-']
     main()
     out, err = capsys.readouterr()
     assert out == 'Word1Word1\n'
 def test_main_delimiters(self, argv_handler, capsys):
     # delimiters are respected on calls to main
     sys.stdin = StringIO("word1\n")
     sys.argv = ['diceware', '-n', '2', '-d', 'DELIM', '-']
     main()
     out, err = capsys.readouterr()
     assert out == 'Word1DELIMWord1\n'
Exemple #4
0
 def test_main_delimiters(self, argv_handler, capsys):
     # delimiters are respected on calls to main
     sys.stdin = StringIO("word1\n")
     sys.argv = ['diceware', '-n', '2', '-d', 'DELIM', '-']
     main()
     out, err = capsys.readouterr()
     assert out == 'Word1DELIMWord1\n'
 def test_main_wordlist(self, argv_handler, capsys, wordlists_dir):
     # we can pick the wordlist we prefer
     wordlists_dir.join('wordlist_foo.txt').write("foo\n")
     wordlists_dir.join('wordlist_bar.asc').write("bar\n")
     sys.argv = ['diceware', '-w', 'foo']
     main()
     out, err = capsys.readouterr()
     assert out == 'FooFooFooFooFooFoo\n'
 def test_main(self, capsys):
     # we can get a passphrase
     main([])  # call with default options in place
     out, err = capsys.readouterr()
     assert err == ''  # we got no errors
     assert out[-1] == '\n'  # output ends with liebreak
     assert not ('\n' in out[:-1])  # we get one line
     assert len(out) > 5  # we get at least some chars
Exemple #7
0
 def test_main_wordlist(self, argv_handler, capsys, wordlists_dir):
     # we can pick the wordlist we prefer
     wordlists_dir.join('wordlist_foo.txt').write("foo\n")
     wordlists_dir.join('wordlist_bar.asc').write("bar\n")
     sys.argv = ['diceware', '-w', 'foo']
     main()
     out, err = capsys.readouterr()
     assert out == 'FooFooFooFooFooFoo\n'
Exemple #8
0
 def test_main_infile_not_a_file(self, argv_handler, tmpdir):
     # give directory as input
     tmpdir.mkdir("wordlist")
     tmpdir.chdir()
     sys.argv = ['diceware', 'wordlist']
     with pytest.raises(IOError) as infile_error:
         main()
     assert infile_error.value.errno == EISDIR
Exemple #9
0
 def test_main_with_realdice_source(self, argv_handler, capsys, fake_input):
     # we can run main with `realdice` source of randomness
     fake_input(["1", "3"])
     sys.stdin = StringIO("w1\nw2\nw3\nw4\nw5\nw6\n")
     sys.argv = ['diceware', '-r', 'realdice', '-n', '2', '-d', '#', '-']
     main()
     out, err = capsys.readouterr()
     assert out.endswith('W1#W3\n')
Exemple #10
0
 def test_main_infile_not_a_file(self, argv_handler, tmpdir):
     # give directory as input
     tmpdir.mkdir("wordlist")
     tmpdir.chdir()
     sys.argv = ['diceware', 'wordlist']
     with pytest.raises(IOError) as infile_error:
         main()
     assert infile_error.value.errno == EISDIR
Exemple #11
0
 def test_main_specialchars(self, argv_handler, capsys):
     # number of specialchars is respected in calls to main.
     sys.stdin = StringIO("word1\n")
     sys.argv = ['diceware', '-n', '1', '-s', '1', '-']
     main()
     out, err = capsys.readouterr()
     specials = [x for x in out if x in SPECIAL_CHARS]
     assert len(specials) > 0
Exemple #12
0
 def test_main_infile(self, argv_handler, tmpdir, capsys):
     # main() reads custom wordlist if provided
     custom_path = tmpdir.join('mywordlist.txt')
     custom_path.write('mysingleword\n')
     tmpdir.chdir()
     main(['-n', '1', 'mywordlist.txt', ])
     out, err = capsys.readouterr()
     assert out == 'Mysingleword\n'
 def test_main_specialchars(self, argv_handler, capsys):
     # number of specialchars is respected in calls to main.
     sys.stdin = StringIO("word1\n")
     sys.argv = ['diceware', '-n', '1', '-s', '1', '-']
     main()
     out, err = capsys.readouterr()
     specials = [x for x in out if x in SPECIAL_CHARS]
     assert len(specials) > 0
Exemple #14
0
 def test_main_version(self, argv_handler, capsys):
     # we can get version infos.
     sys.argv = ['diceware', '--version']
     with pytest.raises(SystemExit) as exc_info:
         main()
     assert exc_info.value.code == 0
     out, err = capsys.readouterr()
     assert __version__ in out
Exemple #15
0
 def test_main(self, capsys):
     # we can get a passphrase
     main([])  # call with default options in place
     out, err = capsys.readouterr()
     assert err == ''               # we got no errors
     assert out[-1] == '\n'         # output ends with liebreak
     assert not ('\n' in out[:-1])  # we get one line
     assert len(out) > 5            # we get at least some chars
 def test_main_version(self, argv_handler, capsys):
     # we can get version infos.
     sys.argv = ['diceware', '--version']
     with pytest.raises(SystemExit) as exc_info:
         main()
     assert exc_info.value.code == 0
     out, err = capsys.readouterr()
     assert __version__ in out
Exemple #17
0
 def test_main_infile(self, argv_handler, tmpdir, capsys):
     # main() reads custom wordlist if provided
     custom_path = tmpdir.join('mywordlist.txt')
     custom_path.write('mysingleword\n')
     tmpdir.chdir()
     main(['-n', '1', 'mywordlist.txt', ])
     out, err = capsys.readouterr()
     assert out == 'Mysingleword\n'
Exemple #18
0
 def test_main_infile_nonexisting(self, argv_handler, capsys):
     # main() prints error if file does not exist
     # raises the exception if it's other that file not exist
     sys.argv = ['diceware', 'nonexisting']
     with pytest.raises(SystemExit) as exc_info:
         main()
     assert exc_info.value.code == 1
     out, err = capsys.readouterr()
     assert "The file 'nonexisting' does not exist." in err
Exemple #19
0
 def test_main_with_realdice_source(
         self, argv_handler, capsys, fake_input):
     # we can run main with `realdice` source of randomness
     fake_input(["1", "3"])
     sys.stdin = StringIO("w1\nw2\nw3\nw4\nw5\nw6\n")
     sys.argv = ['diceware', '-r', 'realdice', '-n', '2', '-d', '#', '-']
     main()
     out, err = capsys.readouterr()
     assert out.endswith('W1#W3\n')
Exemple #20
0
 def test_main_infile_nonexisting(self, argv_handler, capsys):
     # main() prints error if file does not exist
     # raises the exception if it's other that file not exist
     sys.argv = ['diceware', 'nonexisting']
     with pytest.raises(SystemExit) as exc_info:
         main()
     assert exc_info.value.code == 1
     out, err = capsys.readouterr()
     assert "The file 'nonexisting' does not exist." in err
Exemple #21
0
 def test_main_help(self, argv_handler, capsys):
     # we can get help
     sys.argv = ['diceware', '--help']
     with pytest.raises(SystemExit) as exc_info:
         main()
     assert exc_info.value.code == 0
     out, err = capsys.readouterr()
     expected_path = os.path.join(
         os.path.dirname(__file__), 'exp_help_output.txt')
     with open(expected_path, 'r') as fd:
         expected_output = fd.read()
     assert out == expected_output
Exemple #22
0
 def test_main_help(self, argv_handler, capsys):
     # we can get help
     sys.argv = ['diceware', '--help']
     with pytest.raises(SystemExit) as exc_info:
         main()
     assert exc_info.value.code == 0
     out, err = capsys.readouterr()
     expected_path = os.path.join(os.path.dirname(__file__),
                                  'exp_help_output.txt')
     with open(expected_path, 'r') as fd:
         expected_output = fd.read()
     assert out == expected_output
Exemple #23
0
 def test_main_argv(self, argv_handler):
     # main() handles sys.argv if nothing is provided
     sys.argv = ['diceware', '--help']
     with pytest.raises(SystemExit) as exc_info:
         main()
     assert exc_info.value.code == 0
Exemple #24
0
import diceware
from io import StringIO
import sys
import random
import pyperclip


class Capturing(list):
    def __enter__(self):
        self._stdout = sys.stdout
        sys.stdout = self._stringio = StringIO()
        return self

    def __exit__(self, *args):
        self.extend(self._stringio.getvalue().splitlines())
        del self._stringio  # free up some memory
        sys.stdout = self._stdout


if __name__ == '__main__':
    with Capturing() as output:
        diceware.main(["-d", "-", "-n", "5"])
    word_list = output[0].split("-")
    word_list[random.randint(0, 4)] = str(random.randint(0, 99))
    my_pass = "******".join(word_list)
    #my_pass = str(random.randint(0, 99))+"-"+output[0]
    print(my_pass)
    pyperclip.copy(my_pass)
 def test_main_argv(self, argv_handler):
     # main() handles sys.argv if nothing is provided
     sys.argv = ['diceware', '--help']
     with pytest.raises(SystemExit) as exc_info:
         main()
     assert exc_info.value.code == 0