summaryrefslogtreecommitdiff
AgeCommit message (Collapse)Author
2021-12-25Run unit tests with pytest when building Debian packageOlivier Gayot
By default, pybuild uses the following command to run automatic unit tests: $ python3 -m unittest discover Unfortunately, it does not work with us since unittest is unable to discover our tests. Instead, we rely on pytest which succeeds so far. Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
2021-12-25Make sure unit tests can be run from outside the packageOlivier Gayot
The cards from usr/share are not accessible when running the tests from a temporary directory. This happens for instance when running $ pybuild --test --test-pytest Make sure that this command would succeed by mocking the calls to open. Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
2021-12-25Move WS code outside the main into swiftstory.interface.ws.pyOlivier Gayot
Also, the GameManager object is not created globally anymore when importing the module. Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
2021-12-25Remove annoying print statement from setup.pyOlivier Gayot
Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
2021-12-23Add type annotations to client.py and game.pyOlivier Gayot
Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
2021-12-23Add type annotations to board.pyOlivier Gayot
Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
2021-12-23Add type annotations to player.py and status.pyOlivier Gayot
Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
2021-12-23Avoid dependency on Client from GameOlivier Gayot
Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
2021-12-23Refactor GameManager and add control over game creationOlivier Gayot
GameManager had a method called join_game ; which was not actually doing any joining. Instead, it was just returning a reference to the game that would match the specified game name and language. In case the game would not exist, it would be created before being returned. The function is now renamed find_by_name. Also a new parameter "create" has been added. It is a boolean that controls whether a game would be created if it does not exist. Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
2021-12-23Move FS operation outside the initializer of GameManagerOlivier Gayot
Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
2021-12-23Feed the picks directly to the board, without storing them firstOlivier Gayot
Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
2021-12-23Use an enumeration for the game stateOlivier Gayot
Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
2021-12-23Use a language container rather than a dictionaryOlivier Gayot
Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
2021-12-23Don't store a reference to a client from the playerOlivier Gayot
The only reason why we had a reference was that we were able to send notifications back to the client. Instead, we now store the notifications at the player level. At the client level, we now have a coroutine that waits for notifications from the player and sends them when available. Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
2021-12-23Fix reception of card having wrong indexOlivier Gayot
When sending a card reception notification, we don't want to provide the index from the whole deck. Instead we want to give a counter corresponding to the player's total number of received cards. Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
2021-12-23Make sure our use of websockets package is forwards compatibleOlivier Gayot
It seems that between version 8 and 10 of the websockets package, a redesign of the modules hierarchy was performed. In version 8, when importing "websockets", we would end up with a lot of extra things imported in the websockets namespace. For instance: * websockets.exceptions * websockets.server These extra are no longer imported in recent versions. Therefore, we have to be more explicit when importing features from the websockets package. Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
2021-12-23Add script to run static type checkingOlivier Gayot
Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
2021-12-23Add required annotations to make sure mypy succeedsOlivier Gayot
Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
2021-12-23Add back not so unused module ...Olivier Gayot
Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
2021-12-23Use lowercase module namesOlivier Gayot
Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
2021-12-23Use __main__.py instead of SwiftStory.pyOlivier Gayot
Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
2020-11-02Fix typos in READMEOlivier Gayot
Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
2020-11-02Fix typo s/colletion/collectionOlivier Gayot
Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
2020-11-02also add the JoinError exception typeOlivier Gayot
Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
2020-11-01Add UnsupportedLanguage exceptionOlivier Gayot
Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
2020-11-01Add WrongAction exception and use it instaed of returning errorOlivier Gayot
Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
2020-11-01fix error not propagated when collecting cardsOlivier Gayot
Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
2020-11-01replace calls to print by calls to loggingOlivier Gayot
Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
2020-09-13Add test for joining game without specifying the nameOlivier Gayot
Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
2020-09-13Get rid of extra newlineOlivier Gayot
Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
2020-09-13Use callbacks to handle the opcodesOlivier Gayot
Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
2020-09-13Add test for play_card without card ID specifiedOlivier Gayot
Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
2020-09-13Use f-string instead of + operator to concat stringsOlivier Gayot
Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
2020-09-13Handle exception when JSON received is not an objectOlivier Gayot
Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
2020-09-12Handle JSON with no opcodeOlivier Gayot
Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
2020-09-12Add more tests for invalid commandsOlivier Gayot
Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
2020-09-12Use _ name for unused counterOlivier Gayot
Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
2020-09-12Remove useless use of list comprehensionOlivier Gayot
Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
2020-09-12Fix accidental use of tuple in enumerationOlivier Gayot
Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
2020-09-12Remove unused importsOlivier Gayot
Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
2020-09-12Fix missing module name in exception typeOlivier Gayot
Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
2020-09-12Add requirements.txt fileOlivier Gayot
Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
2020-09-12Add test for invalid JSON receivedOlivier Gayot
Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
2020-09-12Move systemd unit file at the right placeOlivier Gayot
Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
2020-05-28Rename function swiftory connection_handlerOlivier Gayot
Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
2020-05-28Don't use coroutines for functions sending notificationsOlivier Gayot
Functions which generate notifications for clients were all making use of await and async. This is not great because if we add a notification somewhere, we need to change the function to a coroutine and update all invocations (recursively changing all functions to coroutines). Instead, we now add a task to the event loop whenever a notification needs to be generated. This allows to drop the await and async specifiers from mostly everywhere. On the downside, it means that if we send a notification to n clients, we have to register n tasks. Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
2020-05-21Don't pass both the client and the socketOlivier Gayot
Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
2020-05-21Properly handle disconnections from remote endOlivier Gayot
Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
2020-05-21Fix reception of cards after playingOlivier Gayot
Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>
2020-05-21Update version to 0.2Olivier Gayot
Signed-off-by: Olivier Gayot <olivier.gayot@sigexec.com>